Why were window.scrollY and window.scrollX introduced?
Asked Answered
D

4

20

As far as I know, pageXOffset/pageYOffset properties were already available since Netscape 4 era.
And it seems scrollX/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?

Dagney answered 24/9, 2010 at 22:0 Comment(1)
MDN states the following: The pageXOffset property is an alias for the scrollX property: window.pageXOffset == window.scrollX; // always true. This doesn’t answer why, but at least it suggests that the answer to Q2 is no.Marolda
S
7

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.

Seiter answered 5/11, 2010 at 13:14 Comment(2)
Nope, according to the link you provided, pageY/XOffset is an alias to scrollX/Y developer.mozilla.org/en/DOM/window.scrollYBayberry
For cross-browser compatibility, use window.pageYOffset instead of window.scrollY.Quilt
T
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.

Tarnetgaronne answered 25/9, 2010 at 20:33 Comment(5)
thx for the effort but it doesn't answer either of my questions ^^Dagney
pageXOffset and pageYOffset are both IE9+Kalila
@JohnHarding Yes, but at the time of writing that answer IE9 didn't exist yet, at least not in a stable version.Tarnetgaronne
@Tarnetgaronne makes sense, but could be confusing to users finding this page now.Kalila
@JohnHarding Fair enough, I updated the answer to explicitly show the versions I was referring to.Tarnetgaronne
B
-1

As pepkin88 said, pageXOffset (and all pageXY values) are not supported in earlier versions of Internet Explorer. Most of the properties used to locate objects and calculate mouse positions are not part of the W3C standards. From what I remember reading, most of the properties are Microsoft's invention. So when you speak of scrollX and scrollY, you are speaking of the original pageXYOffset values. When standard compliant browsers came along that supported the pageXY properties (not part of Microsoft's model), they decided it would be too confusing to stick with the scrollXY values. So, they switched to a much more logical (in their opinion) version: pageOffset.

In my opinion, I find the scrollXY values more intuitive to use. I will usually have to pause and think, every time I try to decide between screenX, pageX, or clientX. I think they could have come up with more intuitive names for each of the properties. Anyways, none of them are really W3C standard, so I guess conventions aren't really that important in this realm of JavaScript. I'm very glad Microsoft invented them though, because they turn out to be very useful.

Bickering answered 5/11, 2010 at 4:56 Comment(1)
I speak of most of MSDN's properties.Bickering
P
-1

I will try to answer using my common sense, nothing official so sorry if that's not what you meant in your question.

window.scrollY and window.scrollX are used to decide how much the website user has scrolled vertically or horizontally.

This is useful for example in scripts that can only detect the "absolute" position of something in the document and need to place something else on top/beside of it, so using the scrollX and scrollY values they can calculate the proper position.

So probably when demand raised for dynamic scripts like custom tooltip, the people responsible for the JavaScript "framework" answered the call and introduced those properties.

Like I said, not official answer, your Googling will be as good as mine to find such answer. :)

Propagandize answered 5/11, 2010 at 5:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.