Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why were window.scrollY and window.scrollX introduced?

Tags:

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?

like image 527
Knu Avatar asked Sep 24 '10 22:09

Knu


People also ask

What is Window scrollX?

scrollX. The read-only scrollX property of the Window interface returns the number of pixels that the document is currently scrolled horizontally. This value is subpixel precise in modern browsers, meaning that it isn't necessarily a whole number.

What is Window pageXoffset?

The read-only Window property pageYOffset is an alias for scrollY ; as such, it returns the number of pixels the document is currently scrolled along the vertical axis (that is, up or down) with a value of 0.0, indicating that the top edge of the Document is currently aligned with the top edge of the window's content ...

Is Window pageYOffset deprecated?

According to MDN, the pageXoffset and pageYoffset is not deprecated.

What is scrollY Javascript?

The scrollY property returns the pixels a document has scrolled from the upper left corner of the window. The scrollY property is read-only.


2 Answers

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.

like image 176
25 revs, 4 users 83% Avatar answered Oct 01 '22 02:10

25 revs, 4 users 83%


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.

like image 33
pepkin88 Avatar answered Oct 01 '22 03:10

pepkin88