The finish event of the Animation interface is fired when the animation finishes playing, either when the animation completes naturally, or when the Animation.finish() method is called to immediately cause the animation to finish up.
Note: The "paused" play state supersedes the "finished" play state; if the animation is both paused and finished, the "paused" state is the one that will be reported. You can force the animation into the "finished" state by setting its startTime to document.timeline.currentTime - (Animation.currentTime * Animation.playbackRate).
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("finish", (event) => { })
onfinish = (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.
Animation.onfinish is used several times in the Alice in Web Animations API Land Growing/Shrinking Alice Game. Here is one instance where we add pointer events back to an element after its opacity animation has faded it in:
const endingUI = document.getElementById("ending-ui");
const bringUI = endingUI.animate(keysFade, timingFade);
bringUI.pause();
hide(endingUI);
bringUI.onfinish = (event) => {
endingUI.style.pointerEvents = "auto";
};