English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
ThescrollYa read-only property that returns the number of pixels the document has scrolled vertically.
The scrollY property ispageYOffsetalias of the property.
window.scrollY
var x = window.scrollX; var y = window.scrollY;Test See </›
Note: scrollX and scrollY properties are equal to pageXOffset and pageYOffset properties.
The number in the table specifies the first browser version that fully supports the scrollY property:
property | |||||
scrollY | is | 55 | is | is | 9 |
Return value: | A number representing the number of pixels the document has scrolled from the top |
---|
Scroll content100 pixels, and display scrollX and scrollY:
window.scrollBy(100, 100); var x = window.scrollX; var y = window.scrollY;Test See </›
Cross-browser solution (for IE8and earlier versions, use scrollLeft and scrollTop):
var x = (window.scrollX !== undefined) ? window.scrollX : (document.documentElement || document.body.parentNode || document.body).scrollLeft; var y = (window.scrollY !== undefined) ? window.scrollY : (document.documentElement || document.body.parentNode || document.body).scrollTop;Test See </›
Window (Window) Reference:window.pageXOffset property
Window (Window) Reference:window.pageYOffset property
Window (Window) Reference:window.scrollX property
HTML DOM Reference:element .scrollLeft property
HTML DOM Reference:element .scrollTop property