Results 1 to 5 of 5

Thread: detecting div dimensions?

  1. #1
    Join Date
    Feb 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default detecting div dimensions?

    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!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    From Quirksmode.org's page on position:

    Code:
    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;
    }
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2006
    Location
    Arlington, texas
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thats to get the position of the layers
    Code:
    document.getElementById('LayerNAME').style.top
    document.getElementById('LayerNAME').style.left
    if you know a little java scriptyou could take from javascript source
    example
    a fly will circle your mouse
    doesnt work with firefox but i just got an IE tab extension and it worked

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Feb 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks a lot guys!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •