Skip to content

Instantly share code, notes, and snippets.

@danheberden
Forked from addyosmani/vendorPrefix.js
Created April 21, 2011 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save danheberden/933883 to your computer and use it in GitHub Desktop.
Save danheberden/933883 to your computer and use it in GitHub Desktop.
JS snippet for getting the current vendor prefix of a CSS(3) property
function getPrefix( prop ){
var vendorPrefixes = ['Moz','Webkit','Khtml','O','ms'],
style = document.createElement('div').style,
upper = prop.charAt(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
return '';
}
Usage:
console.log(getPrefix('transform'));
console.log(getPrefix('transition'));
@rwaldron
Copy link

I wrote some similar, less comprehensive nonsense in Popcorn.zoom()/rotate() https://github.com/rwldrn/popcorn.zoom/blob/master/popcorn.zoom.js

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