Changing the animationIterationCount property of a <div> element:
document.getElementById("myDIV").style.animationIterationCount = "infinite";
Click the button to make animation play forever!
The animationIterationCount property is not supported in IE, Edge or Safari.
<!DOCTYPE html> <html> <head> <style> div {/*from w w w .ja v a2s . c o m*/ width: 100px; height: 100px; background: red; position: relative; animation: mymove 2s 2; } @keyframes mymove { from {left: 0px;} to {left: 200px;} } </style> </head> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("myDIV").style.animationIterationCount = "infinite"; } </script> <div id="myDIV"></div> </body> </html>
The animationIterationCount property sets or gets how many times an animation should be played.
Property Values
Value | Description |
---|---|
number | A number that defines how many times an animation should be played. Default value is 1 |
infinite | Sets that the animation should be played for ever |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The animationIterationCount property returns a String representing the animation-iteration-count property of an element.