This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2020.
The cancel event of the Animation interface is fired when the Animation.cancel() method is called or when the animation enters the "idle" play state from another state, such as when the animation is removed from an element before it finishes playing.
Note: Creating a new animation that is initially idle does not trigger a cancel event on the new animation.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("cancel", (event) => { })
oncancel = (event) => { }
An AnimationPlaybackEvent. Inherits from Event.
In addition to the properties listed below, properties from the parent interface, Event, are available.
AnimationPlaybackEvent.currentTime Read only
The current time of the animation that generated the event.
AnimationPlaybackEvent.timelineTime Read only
The time value of the timeline of the animation that generated the event.
If this animation is canceled, remove its element.
animation.oncancel = (event) => {
animation.effect.target.remove();
};
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
cancel_event |
75 | 79 | 48 | 62 | 13.1 | 75 | 48 | 54 | 13.4 | 11.0 | 75 | 13.4 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Animation/cancel_event