The Window.scrollBy()
method scrolls the document in the window by the given amount.
Syntax
window.scrollBy(x-coord, y-coord); window.scrollBy(options)
Parameters
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 aScrollToOptions
dictionary.
Examples
To 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' });
Notes
window.scrollBy()
scrolls by a particular amount, whereas window.scroll()
scrolls to an absolute position in the document. See also window.scrollByLines()
and window.scrollByPages()
.
Specification
Specification | Status | Comment |
---|---|---|
CSS Object Model (CSSOM) View ModuleThe definition of 'window.scrollBy()' in that specification. | Working Draft | Initial definition. |
Browser Compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
scrollBy
|
Chrome
Full support 1 |
Edge Full support 79 Full support 79 No support 12 — 79 Notes' Only |
Firefox
Full support 1 |
IE Partial support 11 Partial support 11 Notes' Only |
Opera
Full support 3 |
Safari
Full support 1 |
WebView Android
Full support 1 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
Full support 10.1 |
Safari iOS
Full support 1 |
Samsung Internet Android
Full support 1.0 |
ScrollToOptions parameter
|
Chrome
Full support 45 |
Edge
Full support 79 |
Firefox
Full support Yes |
IE
No support No |
Opera
Full support 32 |
Safari
No support No |
WebView Android
Full support 45 |
Chrome Android
Full support 45 |
Firefox Android
Full support Yes |
Opera Android
Full support 32 |
Safari iOS
No support No |
Samsung Internet Android
Full support 5.0 |
Legend
- Full support
- Full support
- Partial support
- Partial support
- No support
- No support
- See implementation notes.'
- See implementation notes.
Window.scrollBy() by Mozilla Contributors is licensed under CC-BY-SA 2.5.