Javascript Reference - HTML DOM Style animationIterationCount Property








The animationIterationCount property sets or gets how many times an animation should be played.

Browser Support

animationIterationCount No No Yes No No

Syntax

Return the animationIterationCount property:

var v = object.style.animationIterationCount 

Set the animationIterationCount property:

object.style.animationIterationCount='number|infinite|initial|inherit'

Property Values

number
how many times to play the animation. Default value is 1
infinite
play the animation for ever




Technical Details

Default Value: 1
Return Value: A string representing the animation-iteration-count property
CSS Version CSS3

Example

The following code shows how to change the animationIterationCount property of a <div> element.


<!DOCTYPE html>
<html>
<head>
<style> 
div {<!--from  w  w  w . j  a v a 2 s  .  c o  m-->
    width: 100px;
    height: 100px;
    background: red;
    position: relative;
    -webkit-animation: mymove 2s 1;  /* Chrome, Safari, Opera */
    animation: mymove 2s 2;
}

/* Chrome, Safari, Opera */
@-webkit-keyframes mymove {
    from {left: 0px;}
    to {left: 200px;}
}

@keyframes mymove {
    from {left: 0px;}
    to {left: 200px;}
}
</style>
</head>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myDIV").style.WebkitAnimationIterationCount = "infinite";  // Code for Chrome, Safari, and Opera
    document.getElementById("myDIV").style.animationIterationCount = "infinite";
}
</script>
<div id="myDIV"></div>
</body>
</html>

The code above is rendered as follows: