event
Animationiteration — CSS reference
Fires when one iteration ends and another begins, not at the final end of the animation. The event bubbles and identifies the animation by name.
Formal Syntax & Structure
css syntaxcss
element.addEventListener("animationiteration", handler);Working Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>animationiteration</title><style>body{margin:0}#a{padding:8px;background:rgb(232,237,241);color:rgb(0,0,0);box-sizing:border-box}#a{width:100px;height:60px;padding:0;opacity:.3;background:#2855ac;color:white;animation:pulse 1s linear both paused}@keyframes pulse{from{opacity:.2}to{opacity:1}}#a{animation-name:none;animation-duration:100ms;animation-iteration-count:2;animation-play-state:running}</style><body><button id="toggle">Start animation</button><button id="cancel">Cancel</button><div id="a">Animated panel</div><output id="status"></output><script>const a=document.querySelector('#a');document.querySelector('#toggle').onclick=()=>a.style.animationName='pulse';document.querySelector('#cancel').onclick=()=>a.style.animationName='none';for(const n of ['animationstart','animationiteration','animationend','animationcancel'])a.addEventListener(n,e=>document.querySelector('#status').textContent=e.type+' '+e.animationName);</script></body></html>