Search w3schools.com:

SHARE THIS PAGE

Window scrollBy() Method

Window Object Reference 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

scrollBy(xnum,ynum)

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

Internet Explorer Firefox Opera Google Chrome Safari

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 Reference Window Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]