Skip to content

Instantly share code, notes, and snippets.

@ngryman
Created November 8, 2011 22:36
Show Gist options
  • Save ngryman/1349521 to your computer and use it in GitHub Desktop.
Save ngryman/1349521 to your computer and use it in GitHub Desktop.
Vendor prefix detection
(function() {
// Following spec is to expose vendor-specific style properties as:
// elem.style.WebkitBorderRadius
// and the following would be incorrect:
// elem.style.webkitBorderRadius
// Webkit ghosts their properties in lowercase but Opera & Moz do not.
// Microsoft foregoes prefixes entirely <= IE8, but appears to
// use a lowercase `ms` instead of the correct `Ms` in IE9
// More here: http://github.com/Modernizr/Modernizr/issues/issue/21
var domPrefixes = ['Webkit', 'Moz', 'O', 'ms', 'Khtml'],
style = document.createElement('div').style,
pref;
function getProp(prop) {
var upperProp = prop.charAt(0).toUpperCase() + prop.slice(1);
if (pref === undefined) {
pref = null;
for (var i = 0, len = domPrefixes.length; i < len; i++) {
if ((domPrefixes[i] + upperProp) in style) {
pref = domPrefixes[i];
break;
}
}
}
if (prop in style)
return prop;
return pref ? pref + upperProp : undefined;
}
this.caps = {
transition: getProp('transition'),
transitionEnd: getProp('transitionEnd')
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment