<!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 let the DIV element keep the styles set by the last keyframe: to {left:200px;}, when the animation is finished.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
document.getElementById("myDIV").style.WebkitAnimationFillMode = "forwards"; // Code for Chrome, Safari, and Opera
document.getElementById("myDIV").style.animationFillMode = "forwards";
}
</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 animationFillMode property is only supported in Firefox.</p>
<div id="myDIV"></div>
</body>
</html>