Scroll the content by 100 pixels, and alert the pageXOffset and pageYOffset:
More "Try it Yourself" examples below.
The pageXOffset and pageYOffset properties returns the pixels the current document has been scrolled from the upper left corner of the window, horizontally and vertically.
The pageXOffset and pageYOffset properties are equal to the scrollX and scrollY properties.
These properties are read-only.
The numbers in the table specify the first browser version that fully supports the property.
Property | |||||
---|---|---|---|---|---|
pageXOffset | Yes | 9.0 | Yes | Yes | Yes |
pageYOffset | Yes | 9.0 | Yes | Yes | Yes |
Note: For IE8 and earlier, you can use "document.documentElement.scrollLeft" and "document.documentElement.scrollTop" instead (See "More Examples" below).
Return Value: | A Number, representing the number of pixels that the document has already been scrolled from the upper left corner of the window, horizontally and vertically |
---|
A cross-browser solution (using scrollLeft and scrollTop for IE8 and earlier):