Welcome to WebmasterWorld Guest from 35.175.191.168

Forum Moderators: open

Message Too Old, No Replies

How to determine the relative position of an element?

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

New User

10+ Year Member

joined:Nov 3, 2003
posts:12
votes: 0


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)?

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 21, 2002
posts:977
votes: 0



window.pageYOffset

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