Thomas Kelly
Thomas Kelly

Reputation: 21

Chrome and Firefox not firing scroll event when reaching the top of the page

I need to be able to detect when the user scrolls to the top of the page, i.e. when scrollTop <= 0. In Chrome and Firefox, if a user scrolls fast enough, the scroll event is not guaranteed to always fire when the user reaches the top of the page. For example, if a user is 1500px down the page, and quickly scrolls up, the scrollTop value captured inside the last scroll event could be 1200.

Safari's fix for this is to fire scroll events for over-scrolling, so scrollTop can be a negative value.

One option would be to listen to both scroll and mousewheel events, but that may not be super performant and still doesn't solve the issue of the user scrolling very fast by grabbing the scroll bar on the side of the page.

What is the best way to detect when the user reaches the top of the page?

Upvotes: 1

Views: 837

Answers (1)

Andr&#233; IT
Andr&#233; IT

Reputation: 45

I think that if the scroll event is not guaranteed to always fire when the user reaches the top of the page, you can use the "setinterval" to verify the scrollTop at every second.

http://www.w3schools.com/jsref/met_win_setinterval.asp

see you

Upvotes: 1

Related Questions