SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculating offsetTop/offsetLeft in IE/Firefox

    Hello all,
    Does anyone have a sure fire way of getting the same offsetTop/offsetLeft for a given element - regardless of how many other elements it's nested in - from IE/Firefox/Opera/etc.?

    I've got an onclick function that I would like to establish the position of the clicked element relative to the browser window...NOT the element's parent. The reason I mention that is because it seems firefox/opera calculate the elements position in that manner while IE 7, apparently, considers that parent element.

    Is there a good browser-juggling function that will give me that result?

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many JavaScript libraries have implemented methods for this. One of them is Yahoo's YUI library. Check out the getX method in that library.

    Alternatively, search this JavaScript forum, this question has been asked many times before.

  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On that point about Javascript libraries...I actually found the corresponding function in mootools, which I'm using.

    Thanks for the help!


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
  •