Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: check IF page is at the top

Is there a way to check, with JavaScript, if the page is at scroll(0,0)?

Reason being I've got a full page slider that I need to pause the second the page is not at origin.

And it might not necessarily be because the page is being scrolled live as I've got internal HTML # links that would load the page right to a scrolled point without actually scrolling.

So the check needs to be is the page not at the top, as opposed to, has the page been scrolled.

like image 907
Seamus O'Hara Avatar asked Nov 21 '11 20:11

Seamus O'Hara


People also ask

How do I check if a div is scrolled to the bottom?

To detect when a user scrolls to bottom of div with React, we can check if the sum of the scrollTop and clientHeight properties of a scrollable element is equal to the scrollHeight property of the same element. We call the useRef hook to create a ref and we assign the returned ref to the inner div, which is scrollable.

How do you find end of scroll?

To detect scroll end with JavaScript, we can listen to the scroll event. Then in the event listener, we check if offsetHeight + scrollTop is bigger than or equal to scrollHeight . We get the div with document. querySelector .


1 Answers

Try this:

document.body.scrollTop === 0 
like image 50
Esailija Avatar answered Sep 30 '22 12:09

Esailija