1.
<body><input id= "btn" type= "button" value= "buttons" ><div id= "div" ></div><script>varbtn= document.getElementById (' btn ')); varOdiv=document.getelementbyid ("div"); //var timer=null;Odiv.timer=NULL; Btn.onclick=function() {clearinterval (Odiv.timer);//prevent the animation in the execution process, artificial in the constant click button, constantly generate timers Odiv.timer=setinterval (function(){ varSpeed =getstyle (Odiv, ' left ', 50);//Odiv move to the right 50px if(speed>900) { speed=900; } odiv.style.left=speed+ ' px ';//move 10px every 0.1s to the right if(speed==900) {//Stop Movingclearinterval (Odiv.timer); alert (speed); } },200); } functionGetStyle (obj,attr,step) {//why parseint (), because Obj.currentstyle[attr] got the 30px-->30 returnparseint (Obj.currentstyle?obj.currentstyle[attr]:getcomputedstyle (obj) [attr]) +step; }</script></body>
2016-05-30 Timer