handle source
—
v151 · javascript · web animations
The animation is declared in pure CSS. The moment it starts, event.animation hands you its Web Animations handle — so a button can pause, reverse, retime, or cancel it.
let handle = null;
orbit.addEventListener("animationstart", (event) => {
// event.animation is nullable (CSSAnimation?) — reject a missing handle.
const animation = event.animation;
if (!animation) return;
handle = animation;
});
pauseBtn.onclick = () => handle?.pause();
reverseBtn.onclick = () => handle?.reverse();
speedBtn.onclick = () => { if (handle) handle.playbackRate = 3; };
cancelBtn.onclick = () => handle?.cancel();