Created
August 21, 2019 08:10
-
-
Save wuhhh/38baeb747aa48d07985bbdb41304eaf3 to your computer and use it in GitHub Desktop.
Get element outer height
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
| /** | |
| * Returns the element height including margins | |
| * @param element - element | |
| * @returns {number} | |
| */ | |
| function outerHeight(element) { | |
| const height = element.offsetHeight, | |
| style = window.getComputedStyle(element) | |
| return ['top', 'bottom'] | |
| .map(side => parseInt(style[`margin-${side}`])) | |
| .reduce((total, side) => total + side, height) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment