Animation: cancel event
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{ APIRef("Web Animations") }}
The **cancel** event of the {{domxref("Animation")}} interface is fired when the {{domxref("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.
توجه: Creating a new animation that is initially idle does not trigger a cancel event on the new animation.
Syntax
Use the event name in {{domxref("EventTarget/addEventListener", "addEventListener()")}}:
addEventListener("cancel", (event) => { })Alternatively, assign to the event handler property of the interface:
oncancel = (event) => { }Event type
An {{domxref("AnimationPlaybackEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("AnimationPlaybackEvent")}}
Examples
If this animation is canceled, remove its element.
animation.oncancel = (event) => {
animation.effect.target.remove();
};Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- Web Animations API
- {{domxref("Animation")}}