Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

detecting css transition support with modernizr

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?

enter image description here

<script type="text/javascript">
// modernizr
</script>


<script type="text/javascript">
    if(!Modernizr.csstransitions) { 
     // Use jquery if CSS transitions are not supported
    }
</script>
like image 637
NL500 Avatar asked Aug 07 '11 10:08

NL500


People also ask

Do you still need modernizr?

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.

What is modernizr how modernizr works?

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.


3 Answers

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)}
        );
    });
}
like image 165
Faraz Kelhini Avatar answered Oct 31 '22 21:10

Faraz Kelhini


CSS Transactions don't exist, I think you are looking for CSS transitions. It's at the bottom of the CSS3 column.

like image 37
ZippyV Avatar answered Oct 31 '22 22:10

ZippyV


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.

like image 4
Rich Bradshaw Avatar answered Oct 31 '22 22:10

Rich Bradshaw