CSS3 Animations: Animation-Play-State

The animation-play-state property specifies whether the animation is running or paused. It needs a script to be useful though. The following is the syntax, along with the possible values:

animation-play-state: paused|running|initial|inherit;

HTML file: Displayed by browser:
<style>
div {
    width: 100px;
    height: 100px;
    background-color: red;
    position: relative;
    padding: 5px;
    -webkit-animation: mymove 2s infinite; /* Chrome, Safari, Opera */
    -webkit-animation-play-state: paused; /* Chrome, Safari, Opera */
    animation: mymove 2s infinite;
    animation-play-state: paused;
}
div {
/* Chrome, Safari, Opera*/
@-webkit-keyframes mymove {
    from {left: 0px;}
    to {left: 200px;}
}
/* The animation code in Standard syntax*/
@keyframes mymove {
    from {left: 0px;}
    to {left: 200px;}
}
</style>
<script>
function myPlayFunction() {
    document.getElementById("myDIV").style.WebkitAnimationPlayState = "running"; // Code for
Chrome, Safari, and Opera
    document.getElementById("myDIV").style.animationPlayState = "running";
}
function myPauseFunction() {
    document.getElementById("myDIV").style.WebkitAnimationPlayState = "paused"; // Code for
Chrome, Safari, and Opera
    document.getElementById("myDIV").style.animationPlayState = "paused";
}
</script>
<body>
<p>Click the buttons to Play/Pause the animation:</p>
<button onclick="myPlayFunction()">Play</button>
<button onclick="myPauseFunction()">Pause</button>
<br /><br />
<div id="myDIV"></div>
</body>

Click the buttons to Play/Pause the animation:



Note: The animationPlayState property is not supported in Internet Explorer 9 and earlier versions.

Back button Table of Contents Next button