[JavaScript]滑鼠拖動
來源:互聯網
上載者:User
代碼很簡單:
<div id="divMove" style="POSITION: absolute;left:300;top:300" onselectstart="return false" onmousedown="MouseDown(this)" onmousemove="MouseMove()"><br /><table width="150" cellpadding="0" cellspacing="0" border="1"><br /><tr><br /><td height="30" bgcolor="#cccccc">title</td><br /></tr><br /><tr><br /><td height="100"><p align="center">testMove</p></td><br /></tr><br /></table><br /></div><br /><SCRIPT LANGUAGE="JavaScript"><br /><!--<br />var currentMoveObj = null;<br />var relLeft,relTop;<br />function MouseDown(obj)<br />{<br />currentMoveObj = obj;<br />currentMoveObj.style.position = "absolute";<br />relLeft = event.x - currentMoveObj.style.pixelLeft;<br />relTop = event.y - currentMoveObj.style.pixelTop;<br />}<br />window.document.onmouseup = function()<br />{<br />currentMoveObj = null;<br />}<br />function MouseMove()<br />{<br />if(currentMoveObj != null)<br />{<br />currentMoveObj.style.pixelLeft=event.x-relLeft;<br />currentMoveObj.style.pixelTop=event.y-relTop;<br />}<br />}</p><p>//--><br /></SCRIPT>