I'm going to use css transition and a jquery plugin as fallback for browsers that don't support it. I want to use modernizr to detect css transition support. It's overkill to load entire library for this, i only want to grab the portion of code i need to detect css transition. in the download page of modernizr there are a lot of options and extras which confuse me. My question is what options should i select to efficiently detect css transition?
<script type="text/javascript">
// modernizr
</script>
<script type="text/javascript">
if(!Modernizr.csstransitions) {
// Use jquery if CSS transitions are not supported
}
</script>
Using the feature detection support, developers can test some of the newer technologies and provide fallbacks for browsers that do not support those technologies. Modernizr is important because it provides an easy way to detect any new feature, whether or not it is compatible with the browser.
Modernizr is a JavaScript library that detects which HTML5 and CSS3 features your visitor's browser supports. In detecting feature support, it allows developers to test for some of the new technologies and then provide fallbacks for browsers that do not support them.
Here is the code you need from the Modernizr library. It's only 1kb.
;window.Modernizr=function(a,b,c){function z(a,b){var c=a.charAt(0).toUpperCase()+a.substr(1),d=(a+" "+m.join(c+" ")+c).split(" ");return y(d,b)}function y(a,b){for(var d in a)if(j[a[d]]!==c)return b=="pfx"?a[d]:!0;return!1}function x(a,b){return!!~(""+a).indexOf(b)}function w(a,b){return typeof a===b}function v(a,b){return u(prefixes.join(a+";")+(b||""))}function u(a){j.cssText=a}var d="2.0.6",e={},f=b.documentElement,g=b.head||b.getElementsByTagName("head")[0],h="modernizr",i=b.createElement(h),j=i.style,k,l=Object.prototype.toString,m="Webkit Moz O ms Khtml".split(" "),n={},o={},p={},q=[],r,s={}.hasOwnProperty,t;!w(s,c)&&!w(s.call,c)?t=function(a,b){return s.call(a,b)}:t=function(a,b){return b in a&&w(a.constructor.prototype[b],c)},n.csstransitions=function(){return z("transitionProperty")};for(var A in n)t(n,A)&&(r=A.toLowerCase(),e[r]=n[A](),q.push((e[r]?"":"no-")+r));u(""),i=k=null,e._version=d,e._domPrefixes=m,e.testProp=function(a){return y([a])},e.testAllProps=z;return e}(this,this.document);
For example you can fall back with the following code and serve up jQuery powered animations to browsers which don't support CSS3 Transitions:
if (!Modernizr.csstransitions) {
$(document).ready(function(){
$(".test").hover(function () {
$(this).stop().animate({ color: "#F00" },700)
}, function() {
$(this).stop().animate({ color: "#AAA" },700)}
);
});
}
CSS Transactions don't exist, I think you are looking for CSS transitions. It's at the bottom of the CSS3 column.
Just tick the CSS transitions box. It will automatically tick a few boxes on the bottom right, I'd leave "Add CSS Classes" and "HTML5 Shim/IEPP", as both are very lightweight, and are useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With