Simple prefixed CSS support checker
Last active
April 18, 2017 16:22
-
-
Save shshaw/244bb2b2d5d30de2d4fe7ef4182fd0ed to your computer and use it in GitHub Desktop.
checkStyleSupport()
This file contains hidden or 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
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