body.scrollTop vs documentElement.scrollTop vs window.pageYOffset vs window.scrollY

I'm using three of them in the skrollr source

return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;

https://github.com/Prinzhorn/skrollr/blob/b98d40820b9864be275e81af382045d72cc5a08a/src/skrollr.js#L627

a) So far it's working across all browsers (nobody complaint in the past year).

b) Since it will use the first one that is defined, I guess it's pretty future proof and stable.

If you're fancy you could do this as well

Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop)

Given that skrollr does not use window.scrollY, this may have been obvious, but as further answer to the original question: window.pageYOffset is an alias for window.scrollY. See Window.scrollY.


To Prinzhorn's answear:

Since body and documentElement is undefined in Chrome/Firefox, better use:

return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;

Tested myself.