W3Schools.com

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 type="text/javascript">
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
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE