Scroll the document to the horizontal position 500:
window.scrollTo(500, 0);
Try it Yourself »
Scroll the document to the vertical position 500:
window.scrollTo(0, 500);
Try it Yourself »
More examples below.
The scrollTo()
method scrolls the document to specified coordinates.
For the scrollTo()
method to work, the document must be larger than the screen, and the scrollbar must be visible.
window.scrollTo(
x, y)
scrollTo(
x, y)
Parameter | Description |
x | Required. The coordinate to scroll to (horizontally), in pixels. |
y | Required. The coordinate to scroll to (vertically), in pixels. |
NONE |
Scroll the document to position 300 horizontally and 500 vertically:
window.scrollTo(300, 500);
Try it Yourself »
scrollTo()
is supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | Yes |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!