Your Search Results

    Window.scrollY

    « Window

    Summary

    Returns the number of pixels that the document has already been scrolled vertically.

    Syntax

    var y = window.scrollY;
    • y is the number of pixels that the document is currently scrolled from the top.

    Example

    // make sure and go down to the second page 
    if (window.scrollY) {
      window.scroll(0, 0);  // reset the scroll position to the top left of the document.
    }
    
    window.scrollByPages(1);

    Notes

    Use this property to check that the document hasn't already been scrolled some if you are using relative scroll functions such as window.scrollBy, window.scrollByLines, or window.scrollByPages.

    The pageYOffset property is an alias for the scrollY property:

    window.pageYOffset == window.scrollY; // always true

    For cross-browser compatibility, use window.pageYOffset instead of window.scrollY. Additionally, older versions of Internet Explorer (< 9) do not support either property and must be worked around by checking other non-standard properties. A fully compatible example:

    var x = (window.pageXOffset !== undefined) ? window.pageXOffset : (document.documentElement || document.body.parentNode || document.body).scrollLeft;
    var y = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;

    Specification

    See also

    Document Tags and Contributors

    Contributors to this page: Sheppy, Shelby, ethertank, teoli, JesseW, Waldo, Mgjbot, iamanupmenon, Dria
    Last updated by: teoli,
    Hide Sidebar