Created
July 27, 2018 07:46
-
-
Save marco-kretz/c169d421244c749ae713bce8acd9f5d4 to your computer and use it in GitHub Desktop.
Get the absolute width 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 getAbsoluteWidth = (element) => { | |
const style = window.getComputedStyle(element); | |
const attrs = ['width', 'padding-left', 'padding-right', 'margin-left', 'margin-right']; | |
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