CKTIS / JavaScript
Element.animate — keyframes and animation timing
Create animations with Element.animate by defining keyframes and timing options, then control the returned Animation object.
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
const animation = element.animate(keyframes, options);Element.animate creates and starts an animation, returning an Animation. It is a browser Web Animations API, not part of ECMAScript; Node 24 does not establish availability. Check typeof Element.prototype.animate === 'function' in the target browser.
WAAPI keyframes and timing options: keyframes accepts an array of objects or an object containing property-value arrays. offset specifies a position from 0 to 1. options can be milliseconds or an object: duration, delay, iterations, easing, direction, fill. The default value of duration is auto, which resolves to zero on the default time-based timeline but can resolve differently on a scroll-driven timeline. fill does not permanently change inline styles.
The example uses pause() and currentTime to inspect the midpoint without waiting. cancel() removes the effect.
Examples
const box = document.createElement('div');
box.textContent = 'WAAPI';
document.body.append(box);
const animation = box.animate(
[{ opacity: 0 }, { opacity: 1 }],
{ duration: 1000, easing: 'linear', fill: 'both' }
);
animation.pause();
animation.currentTime = 500;
console.log(getComputedStyle(box).opacity);
animation.cancel();
box.remove();Result
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.