Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.pageYOffset vs window.scrollY on IE11

Tags:

Window.scrollY does not show the correct top-scroll value on IE11 but Window.pageYOffset, the alias of Window.scrollY, works as expected. I find confusing the fact that the alias works better than the original property. Could somebody help me understand why? :[

Note - I'm not interested in finding a cross-browser compatible version. The point is that I want to know why an alias on IE11 is not working the same as the value which is being "tracked". I'm not sure if I should deeply focus on some different "aliases" on IE...

like image 794
greg_bor Avatar asked Jun 26 '17 10:06

greg_bor


People also ask

What is the pageYOffset?

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 ...

How do you use scrollY?

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

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.


1 Answers

Window.scrollY is not supported in IE(11 or below). Window.pageYOffset works on "all" browsers including IE9-11. Window.scrollY works on "all" browsers except IE.

IE9 and below should (in most cases) not be supported anymore because using them means no security updates for browser or OS, but IE8 alternative to window.scrollY? explains you can use document.documentElement.scrollTop for lower versions of IE.

like image 189
Balder Avatar answered Sep 20 '22 15:09

Balder