detecting css transition support with modernizr

流过昼夜 提交于 2019-12-03 13:08:55

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.

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