<html>
<head>
<style>
div
{
width:100px;
height:100px;
background:red;
position:relative;
animation:mymove 2s infinite;
animation-play-state:paused;
/*Safari 和 Chrome*/
-webkit-animation:mymove 2s infinite;
-webkit-animation-play-state:paused;
}
@keyframes mymove
{
from {left:0px;}
to {left:200px;}
}
@-webkit-keyframes mymove /*Safari 和 Chrome*/
{
from {left:0px;}
to {left:200px;}
}
</style>
</head>
<body>
<p>点击按钮播放/暂停动画:</p>
<button onclick="myPlayFunction()">播放</button>
<button onclick="myPauseFunction()">暂停</button>
<script>
function myPlayFunction()
{
document.getElementById("myDIV").style.animationPlayState = "running";
document.getElementById("myDIV").style.WebkitAnimationPlayState = "running"; // 针对 Chrome 和 Safari 的代码
}
function myPauseFunction()
{
document.getElementById("myDIV").style.animationPlayState = "paused";
document.getElementById("myDIV").style.WebkitAnimationPlayState = "paused"; // 针对 Chrome 和 Safari 的代码
}
</script>
<p><strong>注意:</strong>Internet Explorer 9 及其之前的版本不支持 animationPlayState 属性。</p>
<div id="myDIV"></div>
</body>
</html>