编辑下面的代码:【加编码】
<html> <head> <style> div { width:100px; height:100px; background:red; position:relative; animation:mymove 2s infinite; /*Safari 和 Chrome*/ -webkit-animation:mymove 2s infinite; } @keyframes mymove { from {left:0px;} to {left:200px;} } @-webkit-keyframes mymove /*Safari 和 Chrome*/ { from {left:0px;} to {left:200px;} } @keyframes myNEWmove { from {width:0px;} to {width:500px;background:blue;} } @-webkit-keyframes myNEWmove /*Safari 和 Chrome*/ { from {width:0px;} to {width:500px;background:blue;} } </style> </head> <body> <p>点击“尝试一下”按钮改变动画中要使用的关键帧:</p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction() { document.getElementById("myDIV").style.animationName = "myNEWmove"; document.getElementById("myDIV").style.WebkitAnimationName = "myNEWmove"; // 针对 Chrome 和 Safari 的代码 } </script> <p><strong>注意:</strong>Internet Explorer 9 及其之前的版本不支持 animationName 属性。</p> <div id="myDIV"></div> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂