Why were window.scrollY and window.scrollX introduced?
Solution 1
Is there a browser which implements scrollY/X but doesn't support pageY/XOffset
I guess what you want to know is whether you can fully trust pageY/XOffset
and leave scrollY/X
out of the game. The answer is yes. pageY/XOffset
is working in Firefox, Chrome, Opera, and IE 9!
I can't test scrollX/Y
on IE9 currently, but it is not listed on MSDN properties so there is a good chance it answers your question. So there may be browsers implementing pageY/XOffset
but not scrollY/X
.
Why were window.scrollY and window.scrollX introduced?
As scrollY
is only an alias, I'm sure it is only for better readability.
Solution 2
Everything about it. As you can see pageXOffset
isn't supported by Internet Explorer 8 and below. In IE8 (and lower) you should use scrollLeft
/ scrollTop
of document.body
or document.documentElement
depending what works (just like it is implemented in jQuery).
You can check it here: http://jsfiddle.net/8RFAn/1/
And I don't know why window.scrollX/Y
were introduced, for me these properties looks like pageX/YOffset
in terms of effect and browsers in which are implemented.
Knu
Updated on June 13, 2022Comments
-
Knu about 2 years
As far as I know,
pageXOffset/pageYOffset
properties were already available since Netscape 4 era.
And it seemsscrollX/scrollY
were introduced circa Netscape 6.Alternative question:
Q2. Is there a browser which implements scrollX/scrollY but doesn't support pageXOffset/pageYOffset?
I will add a third question because no one was able to answer the previous ones:
Q3. scrollX/scrollY was added to the latest editor's draft of the CCSOM and the working draft only got pageXOffset/pageYOffset, why are they keeping both attributes?
-
Knu over 13 yearsthx for the effort but it doesn't answer either of my questions ^^
-
Azmisov over 13 yearsI speak of most of MSDN's properties.
-
Michael almost 10 yearsNope, according to the link you provided, pageY/XOffset is an alias to scrollX/Y developer.mozilla.org/en/DOM/window.scrollY
-
Dan Dascalescu almost 9 years
For cross-browser compatibility, use window.pageYOffset instead of window.scrollY.
-
John Harding over 7 yearspageXOffset and pageYOffset are both IE9+
-
pepkin88 over 7 years@JohnHarding Yes, but at the time of writing that answer IE9 didn't exist yet, at least not in a stable version.
-
John Harding over 7 years@pepkin88 makes sense, but could be confusing to users finding this page now.
-
pepkin88 over 7 years@JohnHarding Fair enough, I updated the answer to explicitly show the versions I was referring to.