<!doctype html> <html> <head> <meta charset="utf-8"> <title>定时器</title> <style> div {auto; height:100px; background:white; float:left; } #div1 {position:absolute; background:#F00; height:100px; 100px; left:0px; } /* #div2 {background:#0F0; height:100px; 100px; } #div3 {background:#00F; height:100px; 100px; } #div4 {background:#FF0; height:100px; 100px; } #div5 {background:#0FF; height:100px; 100px; }*/ </style> <script> window.onload=function() { setInterval(function() { var oDiv1=document.getElementById('div1'); oDiv1.style.left=oDiv1.offsetLeft+20+'px'; if(oDiv1.offsetLeft==1000) { oDiv1.style.left=0+'px'; } }, 100); }; </script> </head> <body> <div> <div id='div1'></div> <!--<div id='div2'></div> <div id='div3'></div> <div id='div4'></div> <div id='div5'></div> --> </div> </body> </html>