<! Doctype>/ * Set left value otherwise div will always move to the right * /</style><script type= "Text/javascript" >var timer = null; function Startmove () {var oDiv1 = document.getElementById ("Div1"); Clearinterval (timer); //turn off the timer first (solve the problem of multiple clicks to turn on several timers simultaneously)Timer = setinterval (move,30), function Move () {var ispeed = 1;if (odiv1.offsetleft >= 400) {//when the movement to the distance left is greater than or equal to 400 pixels is to turn off the timer (or to determine when the odiv1.offsetleft<400 +10px operation)Clearinterval (timer);//If it is simply used if the trigger onclick event is clicked again when shipped to stop, the DIV will move 10px to the right again because the timer is called again, and after the timer is closed, the code after it is executed}else{odiv1.style.left = odiv1.offsetleft + ispeed + "px";}} </script>
JS Sport 1