test
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> <style type="text/css"> #box { width: 100px; height: 100px; background: deeppink; position: absolute; left: 0; text-align: center; line-height: 100px; color: #fff; } </style> </head> <body> <div id="box"></div> <script> var i = -200; var oBox = document.getElementById("box"); function Move(){ i += 20; oBox.style.left = i + 'px'; if(i>= (document.body.clientWidth - 110)) { clearInterval(timer); } } var timer = setInterval(Move,10); </script> </body> </html>
博客