JavaScript onanimationiteration Event

You are Here:

JavaScript onanimationiteration Event

The onanimationiteration event occurs when an iteration of a CSS Animation ends, and another one begins.

Note: 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.

onanimationiteration Event as Attribute

Example

HTML Online Editor
<!DOCTYPE html> <html> <head> <style> h2 { color: blue; -webkit-animation: myMultiColor 1s infinite; animation: myMultiColor 1s infinite; } /* Safari 4.0 - 8.0 */ @-webkit-keyframes myMultiColor { from {color: blue;} to {color: green;} } /* Standard syntax */ @keyframes myMultiColor { from {color: blue;} to {color: green;} } </style> </head> <body> <h2 onanimationiteration="myFunction()">Animation is Awesome</h2> <p id="point"></p> <script> var count = 0; function myFunction() { count += 1; var txt = "Iteration Count: "+count; document.getElementById("point").innerHTML = txt; } </script> </body> </html>

Syntax

As Attribute

<element onanimationiteration = "JavaScript">

As Property

window.onanimationiteration = function(){ // code };

Using Event Listener

object.addEventListener("animationiteration" , myScript);

onanimationiteration Event as Property

Example

HTML Online Editor
<!DOCTYPE html> <html> <head> <style> h2 { color: blue; -webkit-animation: myMultiColor 1s infinite; animation: myMultiColor 1s infinite; } /* Safari 4.0 - 8.0 */ @-webkit-keyframes myMultiColor { from {color: blue;} to {color: green;} } /* Standard syntax */ @keyframes myMultiColor { from {color: blue;} to {color: green;} } </style> </head> <body> <h2>Animation is Awesome</h2> <p id="point"></p> <script> var count = 0; var x = document.getElementsByTagName("h2")[0]; function myFunction() { count +=1; var txt = "Iteration Count: "+count; document.getElementById("point").innerHTML = txt; } window.onanimationiteration = myFunction; </script> </body> </html>

Using addEventListener() Method

Note: The addEventListener() method is not supported in Internet Explorer 8 and below.

Example

HTML Online Editor
<!DOCTYPE html> <html> <head> <style> h2 { color: blue; -webkit-animation: myMultiColor 1s infinite; animation: myMultiColor 1s infinite; } /* Safari 4.0 - 8.0 */ @-webkit-keyframes myMultiColor { from {color: blue;} to {color: green;} } /* Standard syntax */ @keyframes myMultiColor { from {color: blue;} to {color: green;} } </style> </head> <body> <h2>Animation is Awesome</h2> <p id="point"></p> <script> var count = 0; var x = document.getElementsByTagName("h2")[0]; function myFunction() { count += 1; var txt = "Iteration Count: "+count; document.getElementById("point").innerHTML = txt; } x.addEventListener("animationiteration", myFunction); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author