Typically, you want set history.scrollRestoration to manual to allow custom transitions.
This API applies to the current entry, which means the scroll state will also NOT be restored when navigating back from external links.
popstateThis means you can always get current scroll position on popstate, but probably not in async callbacks (e.g. Promises). The actual restoration timing is implementation-related: It takes one animation frame in Chrome, and several more in Safari.
To get scroll position, there’s many APIs with different compatibility issues such as:
window.scrollYwindow.pageYOffsetdocument.body.scrollTopdocument.documentElement.scrollTopdocument.scrollingElement.scrollTopHere we don’t examine these APIs one by one, here’s a demo to test with:
Always use scrollTo to scroll your page.
Through scrollY and pageYOffset are NOT readonly, which means they can be set,
they WON’T change anymore once assigned. Take care!
Typically scroll event will be fired on scroll restoration.
Whereas for iOS UIWebview-based browsers no scroll event will be fired.
Try UC browser, Baidubox browser.