Created
July 27, 2018 07:45
-
-
Save marco-kretz/11fdb06fc2191473271b8a1bdfd2a8b7 to your computer and use it in GitHub Desktop.
Get the absolute height of an element.
This file contains 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
const getAbsoluteHeight = (element) => { | |
const style = window.getComputedStyle(element); | |
const attrs = ['height', 'padding-top', 'padding-bottom', 'margin-top', 'margin-bottom']; | |
return attrs | |
.map((k) => parseInt(style.getPropertyValue(k), 10)) | |
.reduce((p, c) => p + c); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment