<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <style> #box{ width:100px; height:100px; background:orange; position: absolute; left:0; } </style> <body> <div id="box"></div> </body> </html> <script> var oBox = document.getElementById(‘box‘); var num = 0 , speed; oBox.onclick = function(){ setInterval(function(){ speed = Math.ceil( 0.1*(1000-num) ); num = num + speed; oBox.style.left = num+‘px‘; },10); } </script>
时间: 2024-10-27 10:20:21