Last active
December 23, 2015 08:09
-
-
Save mtmzorro/6605824 to your computer and use it in GitHub Desktop.
css3 Prefixer
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
/** | |
* css3Prefixer | |
* | |
* Example: document.getElementById('div').setCss3Style('transition', 'translateY(100px) translateX(500px) scale(3)'); | |
*/ | |
Object.prototype.setCss3Style = function(key, value){ | |
if (typeof this.getAttribute !== 'undefined') { | |
var currStyle = this.getAttribute('style'); | |
var prefixs = ["-webkit-", "-moz-", "-o-", "-ms-", ""]; | |
var css3 = ""; | |
if (currStyle !== null) { | |
var styleArr = currStyle.split(';'); | |
var keyReg = new RegExp(key); | |
for (var i = 0; i < styleArr.length; i++) { | |
if (styleArr[i].search(keyReg) !== -1) { | |
styleArr.splice(i, prefixs.length); | |
break; | |
} | |
} | |
css3 = styleArr.join(';'); | |
} | |
for (var i = 0; i < prefixs.length; i++) { | |
css3 += prefixs[i] + key + ':' + value + ';'; | |
} | |
this.setAttribute('style', css3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment