Skip to content

Instantly share code, notes, and snippets.

@wuhhh
Created August 21, 2019 08:10
Show Gist options
  • Select an option

  • Save wuhhh/38baeb747aa48d07985bbdb41304eaf3 to your computer and use it in GitHub Desktop.

Select an option

Save wuhhh/38baeb747aa48d07985bbdb41304eaf3 to your computer and use it in GitHub Desktop.
Get element outer height
/**
* 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