PDA

View Full Version : detecting div dimensions?



mtnyukai
02-07-2006, 07:35 PM
Hi all,

I'm trying to have a div appear once I click on something. I would like the div to follow the mouse where ever it goes, BUT stops following the mouse if the mouse hovers over the div layer (I would set onmousemove = "" if it hovers over a range of specified coordinates, the coordinates where the div would cover.)

So I set a div of 50 x 50 pixels, is there a way to dynamically detect the range of coordinates the div covers, or would I have to set up the range manually within the code?

Or is there something like that already on DD? I tried finding something like that on DD, but I don't think there is.

Any help is much appreciated!

jscheuer1
02-08-2006, 08:40 AM
From Quirksmode.org (http://www.quirksmode.org/js/findpos.html)'s page on position:


function findPosX(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
}
else if (obj.y)
curtop += obj.y;
return curtop;
}

ob1wan
02-09-2006, 07:43 PM
thats to get the position of the layers


document.getElementById('LayerNAME').style.top
document.getElementById('LayerNAME').style.left
if you know a little java scriptyou could take from javascript source
example (http://javascript.internet.com/miscellaneous/fly.html#source)
a fly will circle your mouse
doesnt work with firefox but i just got an IE tab extension and it worked

jscheuer1
02-09-2006, 07:49 PM
Once you know the position of an element, you have its top left corner. If you add in its .offsetWidth you now also have the top right corner. Add to that its .offsetHeight, the bottom right corner, add .offsetHeight alone, you have the bottom left corner. I figured the OP would know this. I could be wrong.

mtnyukai
02-09-2006, 10:47 PM
thanks a lot guys!