Created
January 23, 2015 20:27
-
-
Save abbotto/19a6680bf052e8c64f6e to your computer and use it in GitHub Desktop.
getComputedStyle Polyfill
This file contains hidden or 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
| if (!window.getComputedStyle) { | |
| /** | |
| * @param {(Element|null)} e | |
| * @param {(null|string)=} t | |
| * @return {(CSSStyleDeclaration|null)} | |
| */ | |
| window.getComputedStyle = function(e, t) { | |
| return this.el = e, this.getPropertyValue = function(t) { | |
| /** @type {RegExp} */ | |
| var n = /(\-([a-z]){1})/g; | |
| return t == "float" && (t = "styleFloat"), n.test(t) && (t = t.replace(n, function() { | |
| return arguments[2].toUpperCase(); | |
| })), e.currentStyle[t] ? e.currentStyle[t] : null; | |
| }, this; | |
| }; | |
| } | |
| // EXAMPLE | |
| // Reference: http://snipplr.com/view/13523/ | |
| window.onload = function() { | |
| var compStyle = window.getComputedStyle(document.getElementById('test'), ""); | |
| alert(compStyle.getPropertyValue("color")); | |
| alert(compStyle.getPropertyValue("float")); | |
| alert(compStyle.getPropertyValue("background-color")); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks bro