HTML Window scrollBy() method (original) (raw)

Last Updated : 15 Jun, 2023

The window.scrollBy() method is used to scroll the document by a given number of pixels.

Syntax:

window.scrollBy( xcoordinate, ycoordinate );

or

window.scrollBy(options);

Parameters: This method accepts two parameters as mentioned above and described below:

Note: You can find these options in options in the ScrollToOptions dictionary.

Example 1: Scroll horizontally

HTML `

HTML DOM window scrollby() method

GeeksforGeeks

HTML DOM Window.scrollBy() method

Scroll horizontally!

<script>
    function scrollby() {
        window.scrollBy(100, 0);
    }
</script>

`

Output:

Example 2: Using options

HTML `

HTML DOM Window scrollBy() method

GeeksForGeeks

HTML DOM Window.scrollBy() method

Scroll down

Scroll up

Scroll right

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

`

Output:

Supported Browsers: The browser supported by HTML DOM Window scrollBy() method are listed below: