Skip to content

Instantly share code, notes, and snippets.

@adeubank
Last active December 21, 2015 13:29
Show Gist options
  • Save adeubank/6313285 to your computer and use it in GitHub Desktop.
Save adeubank/6313285 to your computer and use it in GitHub Desktop.
Detect if a browser supports a CSS feature. Courtesy of Stack Overflow. http://stackoverflow.com/questions/10888211/detect-support-for-transition-with-javascript
/**
* Detect if a browser supports a CSS feature.
* Courtesy of Stack Overflow.
* http://stackoverflow.com/questions/10888211/detect-support-for-transition-with-javascript
*
*/
function detectCSSFeature(featurename){
var feature = false,
domPrefixes = 'Webkit Moz ms O'.split(' '),
elm = document.createElement('div'),
featurenameCapital = null;
featurename = featurename.toLowerCase();
if( elm.style[featurename] ) { feature = true; }
if( feature === false ) {
featurenameCapital = featurename.charAt(0).toUpperCase() + featurename.substr(1);
for( var i = 0; i < domPrefixes.length; i++ ) {
if( elm.style[domPrefixes[i] + featurenameCapital] !== undefined ) {
feature = true;
break;
}
}
}
return feature;
}
detectCSSFeature("transition"); // => true or false depending on your browser. Let's hope it's true.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment