[JS]视频总结-第四部分_JavaScript案例-定时器的使用

 

 <!doctype html> <html> <head> <meta charset="utf-8"> <title>定时器</title> <style> div {width:auto; height:100px; background:white; float:left; } #div1 {position:absolute; background:#F00; height:100px; width:100px; left:0px; } /* #div2 {background:#0F0; height:100px; width:100px; } #div3 {background:#00F; height:100px; width:100px; } #div4 {background:#FF0; height:100px; width:100px; } #div5 {background:#0FF; height:100px; width: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> 

 

posted @ 2014-06-06 08:11  It's_Lee  阅读(143)  评论(0编辑  收藏  举报