Skip to content

Instantly share code, notes, and snippets.

@Rplus
Last active August 29, 2015 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rplus/16117dc7b7567ba27162 to your computer and use it in GitHub Desktop.
Save Rplus/16117dc7b7567ba27162 to your computer and use it in GitHub Desktop.
check-css-prop-support
// 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;
}
@Rplus
Copy link
Author

Rplus commented Nov 11, 2014

僅針對 property 判斷 support
不包含 value 判斷

ex: display: flex;

@Rplus
Copy link
Author

Rplus commented Nov 11, 2014

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