JavaScript window.scroll vs. window.scrollTo?

Javascript

Javascript Problem Overview


Any idea what, if any, difference there is between window.scroll(x, y) and window.scrollTo(x, y) [not talking about jQuery]?

Also any ideas as to which browsers support which? Thanks

Javascript Solutions


Solution 1 - Javascript

There are no differences: https://developer.mozilla.org/en/DOM/window.scroll

As far as I know, all major browsers support both.

Solution 2 - Javascript

Window.scrollTo() is effectively the same as the window.scroll(x,y) method. For scrolling a particular distance, use Window.scrollBy().

Also see Window.scrollByLines(), Window.scrollByPages() and Element.scrollIntoView()

MDN - https://developer.mozilla.org/en-US/docs/Web/API/Window/scroll

Solution 3 - Javascript

In the absence of deprecation, I prefer window.scroll instead of window.scrollTo:

  • The specification only describes window.scrollTo by referring to window.scroll, suggesting that window.scroll is authoritative.
  • window.scroll has ~3M search results; window.scrollTo has ~0.5M.

Solution 4 - Javascript

There is scrollTo, scroll, and scrollBy! Apparently there is no standard covering this functionality so all Browsers may not implement it the same.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTomView Question on Stackoverflow
Solution 1 - JavascriptThomas BoniniView Answer on Stackoverflow
Solution 2 - JavascriptjaguarjView Answer on Stackoverflow
Solution 3 - JavascriptjameshfisherView Answer on Stackoverflow
Solution 4 - Javascriptuser195488View Answer on Stackoverflow