X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Window scrollBy() Method

Window Object Reference Window Object

Example

Scroll the document by 100px horizontally:

window.scrollBy(100, 0);

Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

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!


Browser Support

Method
scrollBy() Yes Yes Yes Yes Yes


Syntax

window.scrollBy(xnum,ynum)

Parameter Values

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

Technical Details

Return Value: No return value


Examples

More Examples

Example

Scroll the document by 100px vertically:

window.scrollBy(0, 100);

Try it yourself »

Example

Scroll the document horizontally and vertically:

<button onclick="scrollWin(0, 50)">Scroll down</button>
<button onclick="scrollWin(0, -50)">Scroll up</button>
<button onclick="scrollWin(100, 0)">Scroll right</button>
<button onclick="scrollWin(-100, 0)">Scroll left</button>

<script>
function scrollWin(x, y) {
    window.scrollBy(x, y);
}
</script>

Try it yourself »


Related Pages

Window Object: scrollTo() Method


Window Object Reference Window Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook