< /div>
<script> <br>var bb = document.getElementById("block"); <br>bb.onmousedown = function(){ <br>//Get the current coordinates of the mouse<br>var pageX = event.clientX; <br>var pageY = event.clientY; <br>//Get the coordinates of the block, left border and upper border<br>var offX = parseInt(this.style.left)||0; <br>var offY = parseInt(this.style.top)||0; <br>//Calculate the distance between the mouse coordinates and the block coordinates<br>var offLX = pageX-offX; <br>var offLY = pageY-offY ; <br>if(!document.onmousemove){ <br>document.onmousemove = function(){ <br>bb.style.left=event.clientX-offLX; //Set the X coordinate of block <br>bb. style.top=event.clientY-offLY; //Set the Y coordinate of the block <br>} <br>} <br>} <br>document.onmouseup = function(){document.onmousemove = null;} //Mouse Bounce<br></script>