Window pageYOffset Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window pageYOffset


The pageYOffset property returns the pixels the current document has been scrolled from the upper left corner of the window, vertically.

The pageXOffset and pageYOffset properties are equal to the scrollX and scrollY properties.

These properties are read-only.

Return Value

A Number, representing the number of pixels that the document has already been scrolled from the upper left corner of the window, vertically

The following code shows how to Scroll the content by 100 pixels, and alert the pageXOffset and pageYOffset:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
div {//from ww  w. j av  a  2
    border: 1px solid black;
    background-color: lightblue;
    height: 2000px;
    width: 2000px;

<button onclick="myFunction()" style="position:fixed;">Click me to scroll</button><br><br>


function myFunction() {
    window.scrollBy(100, 100);

    if (window.pageXOffset !== undefined) {
        console.log("Horizontal scroll: " + window.pageXOffset
        + ", Vertical scroll: " + window.pageYOffset);
    } else {
        // IE9 and earlier
        console.log("Horizontal scroll: " + document.documentElement.scrollLeft + ", Vertical scroll: " + document.documentElement.scrollTop);


Related Tutorials