<!DOCTYPE HTML><HTML><HeadLang= "en"> <MetaCharSet= "UTF-8"> <title></title> <style>#div1{width:200px;Height:200px;background:Red;position:Absolute;Top:50px; Left:0px; } </style> <Script> functionStartmove () {varOdiv=document.getElementById ('Div1'); SetInterval (function() {ODiv.style.left=Odiv.offsetleft+Ten+'px'; }, -) } </Script></Head><Body><inputID= "BTN1"type= "button"value= "Start Motion"onclick= "Startmove ()"> <DivID= "Div1" ></Div></input></Body></HTML>
Set pause position and move speed
<!DOCTYPE HTML><HTML><HeadLang= "en"> <MetaCharSet= "UTF-8"> <title></title> <style>#div1{width:200px;Height:200px;background:Red;position:Absolute;Top:50px; Left:0px; } </style> <Script> //Turn on Timer varTimer=NULL; functionStartmove () {var Speed=3; varOdiv=document.getElementById ('Div1'); Timer=SetInterval (function(){ if(Odiv.offsetleft>= -){//Pause Positionclearinterval (timer); } oDiv.style.left=Odiv.offsetleft+ Speed+'px';//speed is how fast the object moves . }, -); } </Script></Head><Body><inputID= "BTN1"type= "button"value= "Start Motion"onclick= "Startmove ()"> <DivID= "Div1" ></Div></input></Body></HTML>
JS Motion Basics