Created
April 21, 2011 06:33
-
-
Save addyosmani/933860 to your computer and use it in GitHub Desktop.
JS snippet for getting the current vendor prefix of a CSS(3) property
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
function getPrefix( prop ){ | |
var vendorPrefixes = ['Moz','Webkit','Khtml','O','ms'], | |
style = document.createElement('div').style, | |
upper = prop[0].toUpperCase() + prop.slice(1), | |
pref, len = vendorPrefixes.length; | |
while( len-- ){ | |
if((vendorPrefixes[len] + upper) in style){ | |
pref = (vendorPrefixes[len]); | |
} | |
} | |
if(prop in style){ | |
pref = prop; | |
} | |
/*exclude additional strings below if output format not an issue*/ | |
if ( pref ) { | |
return '-' + pref.toLowerCase() + '-'; | |
} | |
/*fail safe - thanks to dan for spotting*/ | |
return ''; | |
} | |
Usage: | |
console.log(getPrefix('transform')); | |
console.log(getPrefix('transition')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment