CKTIS / JavaScript
Animation — controlling browser animations
Animation controls playback of an effect on a timeline. It lets you start, pause, and seek an animation independently of its keyframe definition.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
new Animation(effect, timeline)
const animation = element.animate(keyframes, options);Animation controls playback; KeyframeEffect describes keyframes and timing parameters, while DocumentTimeline supplies the timeline. This is a Web API, not part of ECMAScript. Node.js 24 alone does not establish its availability.
new Animation(effect, timeline) does not start playback automatically; element.animate() creates and plays an animation. The methods play(), pause(), reverse(), and cancel() control playback. On a document timeline, currentTime represents milliseconds and can be null.
ready signals completion of a pending play or pause operation; finished signals playback completion. Calling cancel() on an unfinished animation that is not in the idle state rejects its pending finished promise with AbortError. Handle rejection if you use that promise. A newly constructed animation in the idle state has a pending finished promise, which stays pending if you call cancel() while the animation is idle.
The example seeks without starting playback: linear interpolation produces opacity 0.5. Check availability of the APIs used in your target browser.
Examples
const box = document.createElement('div');
box.textContent = 'Animation';
document.body.append(box);
const effect = new KeyframeEffect(
box,
[{ opacity: 0 }, { opacity: 1 }],
{ duration: 1000, easing: 'linear', fill: 'both' }
);
const animation = new Animation(effect, document.timeline);
animation.currentTime = 500;
console.log(animation.currentTime);
console.log(getComputedStyle(box).opacity);
animation.cancel();
box.remove();Result
500 0.5
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.