Window scrollTo() method
- Previous Page scrollBy()
- Next Page scrollX
- Go to the Previous Level Window Object
Definition and usage
scrollTo()
The method scrolls the document to the specified coordinates.
Tip:To make scrollTo()
The method works when the document is larger than the screen, and the scrollbar must be visible.
See also:
instance
Example 1
Scroll the document to horizontal position 500:
window.scrollTo(500, 0);
Example 2
Scroll the document to vertical position 300:
window.scrollTo(0, 500);
Example 3
Scroll the document to horizontal position 300 and vertical position 500:
window.scrollTo(300, 500);
syntax
window.scrollTo(x, y)
or:
scrollTo(x, y)
parameters
parameters | description |
---|---|
x | Required. The coordinate (horizontal) to scroll to, in pixels. |
y | Required. The coordinate (vertical) to scroll to, in pixels. |
Return Value
None.
Browser Support
All Browsers Support scrollTo()
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Previous Page scrollBy()
- Next Page scrollX
- Go to the Previous Level Window Object