function getStylePropValInNum (el, prop) {
if (!prop || typeof prop !== 'string' || !el || el.nodeType !== 1) return 0;
var reg = /(\d*)px/, matchResult, result;
matchResult = el.style[prop].match(reg);
if (matchResult && matchResult.length === 2) {
result = +matchResult[1];
}
return isNaN(result) ? 0 : result;
}
getStylePropValByNum(document.querySelectorAll('div')[0], 'marginTop');
Last active
August 29, 2015 14:20
-
-
Save DaniloShan/0586f806159ae50f7234 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment