Skip to content

Instantly share code, notes, and snippets.

@Rycochet
Created August 15, 2017 11:12
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 Rycochet/1a9933b7fa51a1139c486a9e2ffc5da8 to your computer and use it in GitHub Desktop.
Save Rycochet/1a9933b7fa51a1139c486a9e2ffc5da8 to your computer and use it in GitHub Desktop.
Get the height of the display, based on body - then on the lowest element within the body
/**
* Get the height of the display, based on body height, then the lowest element within it
*/
function getHeight(): number {
var i = 0,
body = document.body,
style = body.style,
elements = document.querySelectorAll("body *"),
best = body.offsetHeight + (parseInt(style.marginTop, 10) || 0) + (parseInt(style.marginBottom, 10) || 0);;
while (i < elements.length) {
let element = elements[i++],
bottom = element.getBoundingClientRect().bottom + (parseInt(getComputedStyle(element).marginBottom, 10) || 0);
if (bottom > best) {
best = bottom;
}
}
return best;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment