Forum Moderators: open

Message Too Old, No Replies

How to determine the relative position of an element?

         

delerious

8:52 am on Dec 7, 2003 (gmt 0)

10+ Year Member



I know how to figure out the top coordinate of an element relative to the top of the document. I can use one of the following:

- document.defaultView.getComputedStyle(document.getElementById(element_id), '').getPropertyValue('top')

- document.getElementById(element_id).offsetTop

But I want to know the top coordinate of an element relative to the top of the viewable area of the browser. Does anyone know how to do this (in IE, Opera, and Mozilla)?

Purple Martin

7:27 am on Dec 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




window.pageYOffset

This tells you how much the document is scrolled down. You should then be able to calculate what you need.