We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

window.scrollX Redirect 1

« window


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


var x = window.scrollX;


  • x is the number of pixels that the document is currently scrolled from the left.


// If scrollX is greater than 400, reset scroll position to the top left of the document.
if (window.scrollX > 400) {


The pageXOffset property is an alias for the scrollX property:

window.pageXOffset == window.scrollX; // always true

For cross-browser compatibility, use window.pageXOffset instead of window.scrollX. 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;


See also

Document Tags and Contributors

Last updated by: Sheppy,