Skip to content

Instantly share code, notes, and snippets.

@shshaw
Last active April 18, 2017 16:22
Show Gist options
  • Save shshaw/244bb2b2d5d30de2d4fe7ef4182fd0ed to your computer and use it in GitHub Desktop.
Save shshaw/244bb2b2d5d30de2d4fe7ef4182fd0ed to your computer and use it in GitHub Desktop.
checkStyleSupport()
var checkStyleSupport = (function() {
var support = {};
var prefixes = ["webkit", "moz", "ms", "o"];
return function(prop) {
if ( support[prop] !== undefined ) { return support[prop]; }
var div = document.createElement('div'),
style = div.style,
ucProp = prop.charAt(0).toUpperCase() + prop.slice(1),
props = (prop + ' ' + (prefixes).join(ucProp + ' ') + ucProp).split(' ');
for (var i in props) {
if ( props[i] in style ) { return support[prop] = props[i]; }
}
return support[prop] = false;
};
}());
console.log( checkStyleSupport('transform') );
/*
var checkSupport = (function() {
var div = document.createElement("div"),
prefixes = ['Khtml', 'O', 'Ms', 'ms', 'Webkit', 'Moz', ''],
valuePrefixes = ['-o-', '-ms-', '-moz-', '-webkit-', ''];
return function(property,value) {
var i = prefixes.length,
prop, support;
while ( i-- ) {
prop = prefixes[i] + property;
if ( prop in div.style ) {
if ( value ) {
div.style[prop] = value;
support = ( div.style[prop] === value );
continue;
} else {
support = prefixes[i] + property;
continue;
}
}
}
return support;
};
}());*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment