Created
December 17, 2017 04:34
-
-
Save robbieferrero/0f1ae910ee7a5db601a531a55a710baa to your computer and use it in GitHub Desktop.
getStyleValue
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
/** | |
* | |
* @param el Element | |
* @param CSS property in hyphen case | |
* @param pseudo pseudo selector (optional) | |
*/ | |
function getStyleValue(el, property, pseudo) { | |
// convert hyphen-case to camelCase | |
const elStyle = el.style[property.replace(/(\-[a-z])/g, $1 => $1.toUpperCase().replace('-',''))]; | |
return ((elStyle !== '' && !pseudo) | |
? elStyle | |
: window.getComputedStyle(el, pseudo).getPropertyValue(property)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment