简体   繁体   中英

How to check where is the scroll when user refreshes the page

I made a navbar which changes it's color when the document's scrolltop is more than 200. But suppose user visit's the page and is in the middle of the page. He refreshes that page now and then the document which now loads is in middle but the properties which are applied are as if the scrolltop is less than 200 and when I move up or down.the scrolltop gets called and my functions are called perfectly but how can I see the current scroll height of the user when he loads the page regardless of the scrolling event being fired?

Here's an example

scrolllessthan200func() #already been called by default 
if (scroll > 200){
    callfunc()
}

How can I do like this when user refreshes the page loads and its scroll height is already more than 200!

if the scroll height is already > 200{
   callfunc()
}
else{
     scrolllessthan200func()

}

Usewindow.scrollY

The read-only scrollY property of the Window interface returns the number of pixels that the document is currently scrolled vertically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM