The solution described at the end of this question (checking for document.scrollingElement
or falling back to document.body
) won’t work on IE, as it doesn’t support document.scrollingElement
(docs), and in IE, the scroll element is the HTML element.
I’d therefore suggest that a better solution for this would be something like;
var scrollNode = document.scrollingElement || document.documentElement;
Which should work for all modern browsers.
As a sidenote, it’s interesting to consider that the scrollingElement
property seems to have been added for the sole purpose of making it so that we don’t need checks/fallbacks for getting the root scrolling element, but due to more browser incompatibilities, we still need a check/fallback in order to use scrollingElement
.
Isn’t web dev fun?