Animation: cancel() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2020.
The Web Animations API's cancel()
method of the Animation
interface clears all KeyframeEffect
s caused by this animation and aborts its playback.
Note:
When an animation is cancelled, its startTime
and currentTime
are set to null
.
Syntax
js
cancel()
Parameters
None.
Return value
None (undefined
).
Exceptions
This method doesn't directly throw exceptions; however, if the animation's playState
is anything but "idle"
when cancelled, the current finished promise is rejected with a DOMException
named AbortError
.
Specifications
Specification |
---|
Web Animations # dom-animation-cancel |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
cancel |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
See also
- Web Animations API
KeyframeEffect
Animation
Animation.playState
Animation.finished
returns the promise this action will reject if the animation'splayState
is not"idle"
.