English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
scrollBy()the method scrolls the document in the window by a specified number of pixels.
scrollBy() scrolls the document by a specified number of pixels, whilewindow.scrollTo()Scroll to the absolute position in the document.
window.scrollBy(x-coord, y-coord)
<button onclick="window.scrollBy(0,10">Click</button>Test See </›
All browsers fully support the scrollBy() method:
Method | |||||
scrollBy() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
x-coord | The horizontal pixel value you want to scroll. Positive values will scroll right, and negative values will scroll left. |
y-coord | The vertical pixel value you want to scroll. Positive values will scroll down, and negative values will scroll up. |
Return Value: | None |
---|
Vertical Scroll Document100 pixels:
<button onclick="window.scrollBy(0, 100);">Click</button>Test See </›
Horizontal and Vertical Scroll Document:
<button onclick="window.scrollBy(0, 50)">Scroll Down</button> <button onclick="window.scrollBy(0, -50)">Scroll Up</button> <button onclick="window.scrollBy(0,100, 0)">Scroll Right</button> <button onclick="window.scrollBy(0,-100, 0)">Scroll Left</button>Test See </›
Window (Window) Reference:window.scrollTo() method
HTML DOM Reference:element.scrollLeft property
HTML DOM Reference:element.scrollTop property