Skip to content

Instantly share code, notes, and snippets.

@marco-kretz
Created July 27, 2018 07:45
Show Gist options
  • Save marco-kretz/11fdb06fc2191473271b8a1bdfd2a8b7 to your computer and use it in GitHub Desktop.
Save marco-kretz/11fdb06fc2191473271b8a1bdfd2a8b7 to your computer and use it in GitHub Desktop.
Get the absolute height of an element.
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