Window scrollBy() Method
Window Object
Definition and Usage
The scrollBy() method scrolls the content 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!
Syntax
| Parameter |
Description |
| xnum |
Required. How many pixels to scroll by, along the x-axis (horizontal) |
| ynum |
Required. How many pixels to scroll by, along the y-axis (vertical) |
Browser Support

The ScrollBy() method is supported in all major browsers.
Example
Example
Scroll the content by 100 pixels:
<html>
<head>
<script>
function scrollWindow()
{
window.scrollBy(100,100)
}
</script>
</head>
<body>
<input type="button" onclick="scrollWindow()" value="Scroll">
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<p>SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL SCROLL</p>
</body>
</html>
Try it yourself »
Window Object
Thank You For Helping Us!
Your message has been sent to W3Schools.
Close [X]