Scrolls the document in the window by the given amount.
window.scrollBy(x-coord, y-coord); window.scrollBy(options)
x-coord is the horizontal pixel value that you want to scroll by.y-coord is the vertical pixel value that you want to scroll by.- or -
options is a ScrollToOptions dictionary.// scroll down one page window.scrollBy(0, window.innerHeight);
To scroll up:
window.scrollBy(0, -window.innerHeight);
Using options:
window.scrollBy({
top: 100,
left: 100,
behavior: 'smooth'
}); window.scrollBy scrolls by a particular amount where window.scroll scrolls to an absolute position in the document. See also window.scrollByLines, window.scrollByPages.
| Specification | Status | Comment |
|---|---|---|
| CSS Object Model (CSSOM) View Module The definition of 'window.scrollBy()' in that specification. | Working Draft | Initial definition. |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | Yes | Partial
|
Yes | 11
|
? | Yes |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | Yes | Yes | ? | Yes | ? | Yes | ? |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/window/scrollBy