Created
August 15, 2017 11:12
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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