<html>
<head>
<style>
#myDIV
{
width:100px;
height:100px;
background:red;
position:relative;
animation:mymove 1s infinite;
-webkit-animation:mymove 1s infinite; /*Safari 和 Chrome*/
}
@keyframes mymove
{
from {left:0px;}
to {left:200px;}
}
@-webkit-keyframes mymove /*Safari 和 Chrome*/
{
from {left:0px;}
to {left:200px;}
}
@keyframes mynewmove
{
from {top:0px;}
to {top:200px;}
}
@-webkit-keyframes mynewmove /*Safari 和 Chrome*/
{
from {top:0px;}
to {top:200px;}
}
</style></head>
<body>
<p>点击“尝试一下”按钮改变 animation 属性的值。</p>
<button onclick="myFunction()">尝试一下</button>
<script>
function myFunction()
{
document.getElementById("myDIV").style.animation = "mynewmove 4s 2";
document.getElementById("myDIV").style.WebkitAnimation = "mynewmove 4s 2"; // 针对 Chrome 和 Safari 的代码
}
</script>
<p><strong>注意:</strong>Internet Explorer 9 及其之前的版本不支持 animation 属性。</p>
<div id="myDIV"></div>
</body>
</html>