SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2009
    Location
    In the hearts of people who passionately hate me
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Position of element

    Hi,

    I'm trying to find the position of an element with respect to the view port area. So, when the user scrolls the page down, I want to know the x and y positions of the element with respect to the viewing (view port) area. Can anyone help with this?

    The overall goal is to know exactly where on the element this user clicked.

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Adil K View Post

    The overall goal is to know exactly where on the element this user clicked.
    Do you need the xy coords relative to the top left hand corner of the clicked element or the viewport?

  3. #3
    SitePoint Member
    Join Date
    Jan 2009
    Location
    In the hearts of people who passionately hate me
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The X&Y coordinates relevant to the element clicked

  4. #4
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When the user clicks an element you can pass the click event to a function.

    The event object's offsetX and offsetY properties will then contain the x and y coords of where the mouse was clicked relative to the element that was clicked.

  5. #5
    SitePoint Member
    Join Date
    Jan 2009
    Location
    In the hearts of people who passionately hate me
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webdev1958 View Post
    When the user clicks an element you can pass the click event to a function.

    The event object's offsetX and offsetY properties will then contain the x and y coords of where the mouse was clicked relative to the element that was clicked.
    Hey,

    Sorry I didn't respond sooner. I got caught up in other things. The offsetX & Y don't seem to be properties accessible at least in FireFox. I didn't bother testing beyond that. Aside from that, I found the solution. You can use the "document.documentElement.scrollTop" to detect the current position of the scrollbar. Since I know the location of the viewing port, I can subtract that from the offset location of the element.

    Thanks for your help. I appreciate it.


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
  •