Window: animationiteration event
The animationiteration event is fired when an iteration of a CSS Animation ends, and another one begins. This event does not occur at the same time as the animationend event, and therefore does not occur for animations with an animation-iteration-count of one.
| Bubbles | Yes |
|---|---|
| Cancelable | No |
| Interface | AnimationEvent |
| Event handler property | onanimationiteration |
The original target for this event is the Element that had the animation applied. You can listen for this event on the Window interface to handle it in the capture or bubbling phases. For full details on this event please see the page on HTMLElement: animationiteration.
Examples
This code uses animationiteration to keep track of the number of iterations an animation has completed:
let iterationCount = 0; window.addEventListener('animationiteration', () => { iterationCount++; console.log(`Animation iteration count: ${iterationCount}`); });
The same, but using the onanimationiteration event handler property:
let iterationCount = 0; window.onanimationiteration = () => { iterationCount++; console.log(`Animation iteration count: ${iterationCount}`); };
See a live example of this event.
Specifications
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
animationiteration_event |
43
1
|
18
≤79
|
51 |
No |
? |
9 |
43
≤37
|
43
18
|
51 |
? |
9 |
4.0
1.0
|
See also
- CSS Animations
- Using CSS Animations
AnimationEvent- Related events:
animationstart,animationend,animationcancel - This event on
Documenttargets:animationiteration - This event on
HTMLElementtargets:animationiteration
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Window/animationiteration_event