Skip to content

Instantly share code, notes, and snippets.

@tunderdomb
Created March 27, 2014 15:42
Show Gist options
  • Select an option

  • Save tunderdomb/9810464 to your computer and use it in GitHub Desktop.

Select an option

Save tunderdomb/9810464 to your computer and use it in GitHub Desktop.
get the scrollable root element on the page
// get the actually scrollable element
function getScrollable( root ){
if ( !root.nodeName || !!~["iframe", "#document", "html", "body"].indexOf(root.nodeName.toLowerCase()) ) {
var doc = (root.contentWindow || root).document || root.ownerDocument || root
root = /webkit/i.test(navigator.userAgent) || doc.compatMode == "BackCompat"
? doc.body
: doc.documentElement;
}
return root
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment