detecting css transition support with modernizr

≡放荡痞女 提交于 2019-12-21 04:15:03

问题


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>

回答1:


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)}
        );
    });
}



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/6972053/detecting-css-transition-support-with-modernizr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!