Created
July 21, 2011 08:23
-
-
Save barneycarroll/1096784 to your computer and use it in GitHub Desktop.
Simple function to determine whether a given CSS property is supported or not. Useful for conditional execution of JS animations, rounded corners, etc.
This file contains 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
// Is the passed CSS property supported? | |
// eg. detectCSS('transition') | |
function detectCSS(prop){ | |
var | |
prop = prop.replace(/-(\w)/g,function(s,g){return g.toUpperCase()}), | |
pre = ',Icab,Khtml,Moz,Ms,O,Webkit'.split(','); | |
for (var i = 0; i < pre.length; ++i){ | |
if(i==1) | |
prop = prop.slice(0,1).toUpperCase() + prop.slice(1); | |
if(pre[i] + prop in document.documentElement.style) | |
return true; | |
} | |
return false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dropped hyphenated notation in favour of camelcase notation for vendor-prefixed property detection, so it works in FF again.