编辑下面的代码:【加编码】
<html> <head> <style> div { width:100px; height:100px; background:red; position:relative; animation:mymove 2s 2; /*Safari、Chrome 和 Opera*/ -webkit-animation:mymove 2s 1; } @keyframes mymove { from {left:0px;} to {left:200px;} } /*Safari、Chrome 和 Opera*/ @-webkit-keyframes mymove { from {left:0px;} to {left:200px;} } </style> </head> <body> <p>点击“尝试一下”按钮让动画永久播放!</p> <button onclick="myFunction()">尝试一下</button> <script> function myFunction() { document.getElementById("myDIV").style.animationIterationCount = "infinite"; // 针对 Chrome、Safari 和 Opera 的代码 document.getElementById("myDIV").style.WebkitAnimationIterationCount = "infinite"; } </script> <p><strong>注意:</strong>对于 Firefox 用户:请确保在动画完成之前点击按钮,否则将不会产生任何影响,因为动画一旦完成不会重头开始播放。</p> <p><strong>注意:</strong>只有 Firefox 支持 animationIterationCount 属性。</p> <div id="myDIV"></div> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂