Example 1 — Count Animations
Start a Web Animation, then read how many are in effect on the document.
const el = document.createElement("div");
document.body.appendChild(el);
el.animate(
[{ opacity: 1 }, { opacity: 0.2 }],
{ duration: 2000, iterations: Infinity }
);
const list = document.getAnimations();
console.log(list.length); // at least 1
console.log(list[0].playState); // "running" How It Works
- Create a target. Append an element so it is in the document.
- Start WAAPI.
animate()returns anAnimationthat stays in effect. - List the page.
getAnimations()includes that animation. - Inspect state.
playStateis often"running"while looping.

