I know that both scroll() and scrollTo() do the same thing and that browsers support both to ensure backwards compatibility, but which one is deprecated? Which one should I be using? And is there a way to prevent a browser from storing the scroll position on a page so that I don't have to use a "beforeunload" event listener to reset my scroll position to (0,0) right before the user leaves the page? I would always like my page to be rendered every time with the scroll position at (0,0), because it's more of an interactive game than a website, and requires this functionality.
W3Schools seems to only reference scrollTo(), so this may be the standard. Still, a workaround for the "beforeunload" event listener would be nice so that my page always starts at scroll position (0,0) without the extra listener.
The W3 actually lists both methods in their spec of the Window interface: http://www.w3.org/TR/cssom-view/#extensions-to-the-window-interface
You can safely use either one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With