Animation: cancel event
Web Animations
Web Animations
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
cancelevent on the new animation.
Syntax
Use the event name in addEventListener():
addEventListener("cancel", (event) => { })
Alternatively, assign to the event handler property of the interface:
oncancel = (event) => { }
Event type
An AnimationPlaybackEvent. Inherits from Event.
AnimationPlaybackEvent
Examples
If this animation is canceled, remove its element.
animation.oncancel = (event) => {
animation.effect.target.remove();
};
Specifications
Browser compatibility
See also
- Web Animations API
- Animation