More "Try it Yourself" examples below.
The scrollBy() method scrolls the document by the specified number of pixels.
Note: For this method to work, the visible property of the window's scrollbar must be set to true!
Method | |||||
---|---|---|---|---|---|
scrollBy() | Yes | Yes | Yes | Yes | Yes |
Parameter | Type | Description |
---|---|---|
xnum | Number | Required. How many pixels to scroll by, along the x-axis (horizontal). Positive values will scroll to the left, while negative values will scroll to the right |
ynum | Number | Required. How many pixels to scroll by, along the y-axis (vertical). Positive values will scroll down, while negative values scroll up |
Return Value: | No return value |
---|
Scroll the document horizontally and vertically:
Window Object: scrollTo() Method