Results 1 to 2 of 2

Thread: Locating elements

  1. #1
    Join Date
    Dec 2005
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Locating elements

    I found a script which very simply reveals a div by id. but I can't get the location just right. It needs to be relative to the object that invokes it through mouseover. Take a look here, mouseover the 'Features' item on the far right. You'll see that I've got the vertical position worked out, although I don't like the way I did it (not dynamic enough), but the horizontal position varies with the width of the window; I want it to be constant relative to the object that invokes it.

    Here's the script:

    Code:
    function showtip(current, whichDiv, whichParent)
    {
      if(document.getElementById)
        {
            elm=document.getElementById( whichDiv );
    	thisParent=document.getElementById( whichParent );
            elml=current;  
            elm.style.top=parseInt(elml.offsetTop+(elml.offsetHeight*2));
            elm.style.left=parseInt(elml.offsetLeft+elml.offsetWidth+345);               
    	elm.style.visibility = "visible"; 
        }
    }
    Thanks in advance. Any help will be greatly 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

    Your code doesn't work in FF. Also offsetHeight, offsetWidth, etc are already integers so the parseInt() method is a waste of time for them. If you really would like to know more about finding the position of things, check out:

    Find position

    from Quirksmode's website. Once you have your target element's position properly identified, a fixed number of pixels distance from it will be where you want to position your pop up division.
    - John
    ________________________

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

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
  •