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
The Window scrollTo() method is used to scroll to a particular set of coordinates in the document. Syntax: window.scrollTo(x-coord, y-coord)
Now you can use just window. scrollTo({ top: 0, behavior: 'smooth' }) to get the page scrolled with a smooth effect.
window. scrollTo(0, document. body. scrollHeight);
Method 1: Using window.scrollTo() The scrollTo() method of the window Interface can be used to scroll to a specified location on the page. It accepts 2 parameters the x and y coordinate of the page to scroll to. Passing both the parameters as 0 will scroll the page to the topmost and leftmost point.
There are no differences: https://developer.mozilla.org/en/DOM/window.scroll
As far as I know, all major browsers support both.
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
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