I want to serve different javascript files depending on if browser supports CSS3 transition or not. Is there a better way to detect transition support than my code below?
window.onload = function () {
var b = document.body.style;
if(b.MozTransition=='' || b.WebkitTransition=='' || b.OTransition=='' || b.transition=='') {
alert('supported');
} else {
alert('NOT supported')
}
}
Modernizr will detect this for you. Use this link to create a custom download build that only contains CSS3 2D and/or 3D transitions.
Once it’s run, you can either test for the
csstransitionsclass on thehtmltag (CSS), or in JavaScript, test ifModernizr.csstransitionsistrue.More docs: http://modernizr.com/docs/#csstransitions