I was just messing around this modernizr to find out, how do they check if a certain CSS property is supported in a user's browser, basically I just wanted to have a small script that told me if the user's browser supports CSS transitions. I abstracted the modernizr code to something like below:
Elem = document.createElement('Alx');
eStyle = Elem.style;
var cssProp = (function check(){
props = ["transition", "WebkitTransition", "MozTransition", "OTransition", "msTransition"];
for(var i in props) {
var prop = props[i];
console.log(prop);
if (!contains('-' , prop) && eStyle[prop] !== undefined ) {
return prop;
}
}
})();
/* The contains function */
function contains( str, substr ) {
return !!~('' + str).indexOf(substr);
}
modernizr does almost the same thing, i have just made a few changes and hard coded the array values to simplify things. The script works in the following way.
Create a html element (Doesn't have to be a valid html element).
execute a IIFE that basically goes through all the possible browser versions of the css property and also the standard W3C variant. check if thing property can be applied to the html element we created, if it can't be applied the
if
condition fails and undefined is returnedif the if condition passed the, the correct css-3 supported property is returned and stored in cssProps .
I just wanted to know, is this a bullet proof way of checking what transition is supported in the user's browser? or if its supported at all?
This is really my first attempt at browser feature detection and so I wanted to know.