企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
~~~ <style> * { margin: 0; padding: 0 } #test { width: 100px; height: 100px; background: #ff2d51; position: absolute; } </style> </head> <body> <button id="btn">动画</button> <div id="test" style="left:0"> </div> <script> // test-->left偏移200 var timer = 100; var btn = document.getElementById("btn"); var test = document.getElementById("test"); var animated = false; // setTimeout btn.onclick = function () { if(animated){ return false; } function go() { animated = true; var valueLeft = parseInt(test.style.left) + 10; test.style.left = valueLeft + "px"; if (parseInt(test.style.left) < 100) { setTimeout(go, timer) } } go(); } </script> ~~~