문제

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.

도움이 되었습니까?

해결책

Use position() instead of offset()

var positionTop = $(this).position().top;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top