When trying to find out how much a web page has been scrolled from the top, which of these should one use:
document.body.scrollTop
,
document.documentElement.scrollTop
,
window.pageYOffset
,
window.scrollY
Which one(s) would I choose in these 2 separate scenarios:
a) If I wanted maximum compatibility (across the main browsers used currently)?
b) If I wanted code that was most standards compliant/future-proof/strict-mode-compatible (but didn't care about supporting old/non-standard browsers)?
I'm using three of them in the skrollr source
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
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)