Skip to content

Instantly share code, notes, and snippets.

@matijs
Forked from dperini/getScrollingElement.js
Last active August 29, 2015 14:06
Show Gist options
  • Save matijs/49f0439eda039b7f0911 to your computer and use it in GitHub Desktop.
Save matijs/49f0439eda039b7f0911 to your computer and use it in GitHub Desktop.
/*
* How to get the scrolling element in charge of scrolling the viewport:
*
* - in Quirks mode the scrolling element is the "body"
* - in Standard mode the scrolling element is the "documentElement"
*
* webkit based browsers always use the "body" element disrespectfull of the specifications:
* http://dev.w3.org/csswg/cssom-view/#dom-element-scrolltop
*/
function getScrollingElement() {
var d = document;
return d.documentElement.scrollHeight > d.body.scrollHeight &&
d.compatMode.indexOf('CSS1') == 0 ?
d.documentElement :
d.body;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment