JQuery fallback for CSS3 transition

微笑、不失礼 提交于 2019-12-03 15:10:19

I think you already have the answer, you should use modernizr, it is not complicated as you think, there are two ways that modernizr specify which are the features available and which are not, the first one is through a set of CSS classes in the HTML element:

<html class="js no-flexbox canvas canvastext postmessage no-websqldatabase ... ">

if it is available it will appear the name, if it is not available it will appear the name with a "no-" preffix like "no-flexbox", the second one is through javascript:

if(!Modernizr.csstransitions)

Modernizr has a set of boolean variables that can tell you if it is available or not, so if you want to set a fallback for your animation I would suggest that you use the Modernizr classes to specify the animation only for the browsers which has this feature:

.csstransitions #element{
-webkit-transition: ... ;
-moz-transition: ... ;
-o-transition: ... ;
-ms-transition: ... ;
transition: ... ;
}

and then create a javascript file with the variables that modernizr has checking if the feature is available, if it is not then specify the animation:

if(!Modernizr.csstransitions)
    $("#element").hover(function(){ $(this).animate({ ... your animation ... }, 5000); });

this might give you an idea how Modernizr works (I hope), anyway if you have a problem you may check this blog post I made a long time ago, it says something like this with some other things like CSS3PIE (this is not spam, I am just trying to help).

Transit translates jQuery animate calls to CSS3 animations and falls back to regular js for unsupported browsers.

Alternatively you can extend $.support to check for transitions like this and use jQuery animate when the test for them fails.

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