<HTML> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /> <title>Mouse Control div Move</title> <Scripttype= "Text/javascript"> var_ismousedown= 0; var_clickleft= 0; var_clicktop= 0; functionMoveinit (evt) {_ismousedown= 1; varobj=Getobjbyid ('Movediv'); _clickleft=Evt.clientx-Obj.offsetleft; _clicktop=Evt.clienty-Obj.offsettop; } functionStartmove (evt) {if(_ismousedown== 0){ return; } varobj=Getobjbyid ('Movediv'); Obj.style.left=Evt.clientx-_clickleft; Obj.style.top=Evt.clienty-_clicktop; } functionStopmove () {_ismousedown= 0; } functionGetobjbyid (ID) {returndocument.getElementById (ID); } </Script> <styletype= "Text/css"rel= "stylesheet">#movediv{width:100px;Height:100px;position:Absolute;Border:1px solid #000;background:#EAEAEA; } </style> </Head> <Body> <DivID= "Movediv"style= "left:20px;top:20px;"onmousedown= "Moveinit (event);"onmousemove= "Startmove (event)"onmouseup= "Stopmove ()"onmouseout= "Stopmove ()"> </Div> </Body></HTML>
html--Mouse Control div move