<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title></title> <style> * {margin:0;padding:0; }Div{Margin-top:10px;width:100px;Height:50px;Background-color:Purple;position:Absolute; } </style></Head><Body><inputtype= "button"value= "Move to 400px"ID= "BT1"/><inputtype= "button"value= "Move to 800px"ID= "BT2"/><DivID= "DV"></Div><Scriptsrc= "Common.js"></Script><Script>my$ ("BT1"). onclick= function () { //gets the current left value of the Div var Left=my$ ("DV"). offsetleft; varStep= Ten; Timeid=SetInterval (function () { if( Left<= -) { left+=step; my$ ("DV"). Style.left= Left+ "px"; Console.log (left); } Else{clearinterval (Timeid); } }, Ten) }; my$ ("BT2"). onclick= function () { //gets the current left value of the Div var Left=my$ ("DV"). offsetleft; varStep= Ten; Timeid=SetInterval (function () { if( Left<= -) { left+=step; my$ ("DV"). Style.left= Left+ "px"; Console.log (left); } Else{clearinterval (Timeid); } }, Ten) };</Script></Body></HTML>
JavaScript Div Move Animation