DHTML: Dynamically Move an Object to Mouse Position

This function will enable to move objects to wherever the mouse is currently pointing. This is very handy for tooltips, when you want to display a help screen depending on the object you're pointing at

function moveObject( obj, e ) {
var tempX = 0;
var tempY = 0;
obj = MM_findObj(obj).style;
if (document.all) {
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
} else {
tempX = e.pageX;
tempY = e.pageY;
if (tempX < 0){tempX = 0} if (tempY < 0){tempY = 0} obj.top = tempY + 'px'; obj.left = tempX + 'px'; } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n= n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i



  1. How do you use this?
    Sorry.. I'm a beginnes with Javascript.

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image