It’s been so long since I had to deal with IE that I had forgotten about this, but IE does not support
window.scrollY; you have to use something like:
var top = typeof window.scrollY === "undefined” ? window.pageYOffset : window.scrollY;
One more teeny difference for the mobile web! :-)
I know this is an old post, but it resolved my issue nicely; thanks for posting.
But (window.scrollY || window.pageYOffset)
as (0 || undefined ) returns undefined
Not sure what you mean, ae…
So, as ae pointed out, if window.scrollY is 0 then it will be seen as false. This will cause your expression to evaluate window.pageYOffset, so the final result will be undefined instead of 0 as it should be.
In order to get around this problem you could use a ternary expression such as:
var top = typeof window.scrollY === “undefined” ? window.pageYOffset : window.scrollY;
Fantastic, thanks, badgerjp2013!
The cross-browser compatible version for `window.scrollY` is `document.documentElement.scrollTop`
Near as I can tell, it isn’t. I spent the last hour trying to get that to play nice across Chrome, Firefox and Safari, and ultimately window.scrollY was the only thing that worked for all of them.