Javascript Reference - HTML DOM Style animationPlayState Property








The animationPlayState property sets and gets whether the animation is running or paused.

Browser Support

animationPlayState Yes (WebkitAnimation) 10 Yes Yes (WebkitAnimation) Yes (WebkitAnimation)

Syntax

Return the animationPlayState property:

var v = object.style.animationPlayState;

Set the animationPlayState property:

object.style.animationPlayState='running|paused|initial|inherit'; 

Property Values

paused
animation is paused
running
Default value. animation is running




Technical Details

Default Value: running
Return Value: A string representing the animation-play-state property
CSS Version CSS3

Example

The following code shows how to pause an animation.


<!DOCTYPE html>
<html>
<head>
<style> 
div {<!--from   w  w w. j a va  2s .co m-->
    width: 100px;
    height: 100px;
    background: red;
    position: relative;
    -webkit-animation: mymove 2s infinite;  /* Chrome, Safari, Opera */
    -webkit-animation-play-state: paused;  /* Chrome, Safari, Opera */
    animation: mymove 2s infinite;
    animation-play-state: paused;
}

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

@keyframes mymove {
    from {left: 0px;}
    to {left: 250px;}
}
</style>
</head>
<body>
<button onclick="myPlayFunction()">Play</button>
<button onclick="myPauseFunction()">Pause</button>

<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>

<div id="myDIV"></div>

</body>
</html>

The code above is rendered as follows: