Question

I am using jQuery's 'offset' to find the coordinates of a div from the top of the page.

I have found some problems between Firefox (27.0.1) and Safari/Chrome (Safari 7.01).

If I use the following:

var positionTop = $('#div').offset().top;

If I scroll down to the bottom of the page and have this variable displayed, it is different into the two browsers.

Firefox is setting the coordinates from the actual page top, where Safari and Chrome are setting it from the top of the viewport!

I have searched google again and again and can't find a solution to this.

Can anyone enlighten me as to how I can have both either measure from the top of the page or top of the viewport?

Thank you.

Was it helpful?

Solution

Use position() instead of offset()

var positionTop = $(this).position().top;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top