检测css过渡支持与modernizr [英] detecting css transition support with modernizr
问题描述
我将使用css transition和一个jquery插件作为不支持它的浏览器的后备。我想使用modernizr来检测css转换支持。它是overkill加载整个库为此,我只想抓住代码的部分,我需要检测css过渡。在modernizr的下载页面中,有很多选项和附加功能让我困惑。我的问题是,我应该选择哪些选项来有效检测css转换?
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>
推荐答案
下面是Modernizr库中需要的代码。只有1kb。
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);
例如,您可以使用以下代码回退并向浏览器提供jQuery动力的动画, t支持CSS3转换:
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过渡支持与modernizr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!