<!DOCTYPE html>
<html>
<head>
<style>
div {
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>
<p>Click the "Try it" button to make animation play forever!</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
document.getElementById("myDIV").style.WebkitAnimationIterationCount = "infinite"; // Code for Chrome, Safari, and Opera
document.getElementById("myDIV").style.animationIterationCount = "infinite";
}
</script>
<p><strong>Note:</strong> For Firefox users: be sure to click the button BEFORE the animation has finished, if not the change will not have any affect because the animation will not start over once it has finished.</p>
<p><strong>Note:</strong> The animationIterationCount property is currently only supported in Firefox.</p>
<div id="myDIV"></div>
</body>
</html>