Skip to content

Instantly share code, notes, and snippets.

@allex
Created February 19, 2012 02:49
Show Gist options
  • Save allex/1861719 to your computer and use it in GitHub Desktop.
Save allex/1861719 to your computer and use it in GitHub Desktop.
Get vendor style prefix
/* vim: set ft=javascript */
// http://addyosmani.com/polyfillthehtml5gaps/slides/#78
function getPrefix(prop){
var prefixes = ['Moz','Khtml','Webkit','O','ms'],
elem = document.createElement('div'),
upper = prop.charAt(0).toUpperCase() + prop.slice(1);
if (prop in elem.style)
return prop;
for (var len = prefixes.length; len--; ){
if ((prefixes[len] + upper) in elem.style)
return (prefixes[len] + upper);
}
return false;
}
console.log(getPrefix('transform'));//WebkitTransform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment