Skip to content

Instantly share code, notes, and snippets.

@abbotto
Created January 23, 2015 20:27
Show Gist options
  • Select an option

  • Save abbotto/19a6680bf052e8c64f6e to your computer and use it in GitHub Desktop.

Select an option

Save abbotto/19a6680bf052e8c64f6e to your computer and use it in GitHub Desktop.
getComputedStyle Polyfill
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"));
}
@EdamAme-x
Copy link

thanks bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment