X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Window scrollBy() Method

Window Object Reference Window Object

Example

Scroll the content by 100px horizontally:

window.scrollBy(100,0);

Try it yourself »


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!


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The scrollBy() method is supported in all major browsers.


Syntax

window.scrollBy(xnum,ynum)

Parameter Values

Parameter Description
xnum 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 left
ynum Required. How many pixels to scroll by, along the y-axis (vertical). Positive values will scroll up, while negative values scroll down

Return Value

No return value.


More Examples

Example

Scroll the content by 100px vertically:

window.scrollBy(0,100);

Try it yourself »

Example

Scroll the content horizontally and vertically:

<button onclick="scrollWin(0,100)">Scroll down</button>
<button onclick="scrollWin(0,-100)">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 »


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 FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook