Skip to content

Instantly share code, notes, and snippets.

@mateuszkocz
Created September 3, 2013 05:19
Show Gist options
  • Save mateuszkocz/6419945 to your computer and use it in GitHub Desktop.
Save mateuszkocz/6419945 to your computer and use it in GitHub Desktop.
Supports for CSS properties in JavaScript. Source: http://ryanmorr.com/detecting-css-style-support
(function(win){
"use strict";
var el = win.document.createElement('div'),
camelRe = /-([a-z]|[0-9])/ig,
cache = {},
support,
camel,
key;
win.isStyleSupported = function(style, value){
value = arguments.length === 2 ? value : 'inherit';
if('CSS' in win && 'supports' in win.CSS){
return win.CSS.supports(style, value);
}
if('supportsCSS' in win){
return win.supportsCSS(style, value);
}
key = style + ':' + value;
if(key in cache){
return cache[key];
}
support = false;
camel = style.replace(camelRe, function(all, letter){
return (letter + '').toUpperCase();
});
support = (typeof el.style[camel] === 'string');
el.style.cssText = style+':'+value;
support = support && (el.style[camel] !== '');
return cache[key] = support;
};
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment