Skip to content

Instantly share code, notes, and snippets.

@dhritzkiv
Created November 21, 2014 01:29
Show Gist options
  • Select an option

  • Save dhritzkiv/d3266cfd1f4b5fdfd436 to your computer and use it in GitHub Desktop.

Select an option

Save dhritzkiv/d3266cfd1f4b5fdfd436 to your computer and use it in GitHub Desktop.
getDocumentScrollElement()
(function() {
document.addEventListener("DOMContentLoaded", function() {
var elm = document.createElement('div');
elm.setAttribute("style", "height:" + (window.innerHeight + 1) + "px;width:1px");
document.body.appendChild(elm);
document.body.scrollTop = 1;
window.scrollElement = document.body.scrollTop > 1 ? document.body : document.documentElement;
window.scrollElement.scrollTop -= 1;
document.body.removeChild(blockElm);
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment