Last active
August 29, 2015 14:02
-
-
Save keenwon/603980ef8a27317eb430 to your computer and use it in GitHub Desktop.
原生js获取元素样式
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
function getCss (el, cssName) { | |
if (el.style[cssName]) { | |
return el.style[cssName]; | |
} else if (el.currentStyle) { | |
return el.currentStyle[cssName]; | |
} else if (document.defaultView && document.defaultView.getComputedStyle) { | |
cssName = cssName.replace(/([A-Z])/g, '-$1'); | |
cssName = cssName.toLowerCase(); | |
var s = document.defaultView.getComputedStyle(el, ''); | |
return s && s.getPropertyValue(cssName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment