Last active
August 29, 2015 14:03
-
-
Save Rplus/16117dc7b7567ba27162 to your computer and use it in GitHub Desktop.
check-css-prop-support
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
// via: | |
// * https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Using_CSS_animations/Detecting_CSS_animation_support | |
// * https://gist.github.com/jackfuchs/556448 | |
$.support.cssProperty = function(prop) { | |
var domPrefixes = ',Webkit,Moz,O,ms,Khtml'.split(','), | |
domPrefixesLength = domPrefixes.length, | |
isSupport = false; | |
for (var i = 0; i < domPrefixesLength; i++) { | |
// i = 0, standard method, do not trans to uppercase | |
if (i) {prop = prop.charAt(0).toUpperCase() + prop.substr(1); } | |
isSupport = (domPrefixes[i] + prop) in document.body.style; | |
if (isSupport) { | |
break; | |
} | |
} | |
return isSupport; | |
} |
use it with jQuery query set:
jqEleCollection.addClass(function checkCssPropSupport() {
var properties = [
$.support.cssProperty('animation'),
$.support.cssProperty('borderRadius'),
$.support.cssProperty('boxShadow')
],
classes = [
'cssanimations',
'borderradius',
'boxshadow'
];
for (var i = properties.length - 1; i >= 0; i--) {
if (!properties[i]) {
classes[i] = 'no-' + classes[i];
}
}
return classes.join(' ');
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
僅針對
property
判斷 support不包含
value
判斷