Skip to content

Instantly share code, notes, and snippets.

@dhunmoon
Created August 16, 2022 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhunmoon/cff05815752f1e8edbdbbd124e0b18d1 to your computer and use it in GitHub Desktop.
Save dhunmoon/cff05815752f1e8edbdbbd124e0b18d1 to your computer and use it in GitHub Desktop.
Get document height
/**
* Document sizes are a browser compatibility nightmare because, although all browsers expose clientHeight and s
* crollHeight properties, they don't all agree how the values are calculated.
* @return {float} Height of the page after calulation.
* */
function getDocumentHeight(){
var body = document.body,
html = document.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
return height
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment