adil_k — 2011-11-11T14:00:28-05:00 — #1
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.
system — 2011-11-11T18:11:31-05:00 — #2
Do you need the xy coords relative to the top left hand corner of the clicked element or the viewport?
adil_k — 2011-11-11T18:15:18-05:00 — #3
The X&Y coordinates relevant to the element clicked
system — 2011-11-11T18:58:13-05:00 — #4
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.
adil_k — 2011-11-15T16:11:09-05:00 — #5
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.