English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
scrollTo()the method scrolls the document to the specified coordinate position.
The scrollTo() method scrolls the document to an absolute position, whilewindow.scrollBy()Scroll the document by the specified number of pixels.
For information on scrollable elements, seeelement.scrollTopandelement.scrollLeft.
window.scrollTo(x-coord, y-coord)
<button onclick="window.scrollTo(5">Click</button>Test and See‹/›
All browsers fully support the scrollTo() method:
Method | |||||
scrollTo() | Is | Is | Is | Is | Is |
Parameter | Description |
---|---|
x-coord | The number of pixels to display on the document horizontal axis at the top left |
y-coord | The number of pixels to display on the document vertical axis, located at the top left corner |
Return Value: | None |
---|
Vertical Document Scrolling500 pixels:
<button onclick="window.scrollTo(0, 500);">Click</button>Test and See‹/›
Horizontal and Vertical Document Scrolling:
<button onclick="window.scrollTo(0, 50)">Scroll Down</button> <button onclick="window.scrollTo(0, -50)">Scroll Up</button> <button onclick="window.scrollTo(300, 0)">Scroll Right</button> <button onclick="window.scrollTo(-300, 0)">Scroll Left</button>Test and See‹/›
Window (Window) Reference:window.scrollBy() method
HTML DOM Reference:element .scrollLeft property
HTML DOM Reference:element .scrollTop property