大佬教程收集整理的这篇文章主要介绍了jQuery中的动画css模糊过滤器,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这作为一种应用CSS规则的静态方式:
item.css({'filter': 'blur('+blur+')','-webkit-filter': 'blur('+blur+')','-moz-filter': 'blur('+blur+')','-o-filter': 'blur('+blur+')','-ms-filter': 'blur('+blur+')'});
item.animate({'filter': 'blur('+blur+')','-ms-filter': 'blur('+blur+')'},500);
有没有一个技巧我不知道?如何动画化项目的模糊性?
$(function() { $({BlurRadius: 0}).animate({BlurRadius: 10},{ duration: 500,easing: 'swing',// or "linear" // use jQuery UI or Easing plugin for more options step: function() { console.log(this.blurRadius); $('.item').css({ "-webkit-filter": "blur("+this.blurRadius+"pX)","filter": "blur("+this.blurRadius+"pX)" }); } }); });
次要更新:jQuery的.animate()可能不会正确地补充到最终值,如another answer below所示.在这种情况下,链接回调将永远更安全,手动将模糊半径设置为预期的最终值.我已经模块化了这些功能,以便可以重复使用,而不需要太多的冗余:
$(function() { // Generic function to set blur radius of $ele var setBlur = function(ele,radius) { $(elE).css({ "-webkit-filter": "blur("+radius+"pX)","filter": "blur("+radius+"pX)" }); },// Generic function to tween blur radius tweenBlur = function(ele,starTradius,endRadius) { $({BlurRadius: starTradius}).animate({BlurRadius: endRadius},{ duration: 500,// or "linear" // use jQuery UI or Easing plugin for more options step: function() { setBlur(ele,this.blurRadius); },callBACk: function() { // Final callBACk to set the target blur radius // jQuery might not reach the end value setBlur(ele,endRadius); } }); }; // Start tweening tweenBlur('.item',10); });
重要的是要注意,Firefox(FF≥35及以上的supports unprefix CSS filters),IE和Opera都有no support for CSS3 filters,所以不需要使用-moz-,-ms-或-o前缀:)
见小提琴:http://jsfiddle.net/teddyrised/c72Eb/(更新前)
有关最新的示例,请参阅下面的代码段:
$(function() { // Generic function to set blur radius of $ele var setBlur = function(ele,complete: function() { // Final callBACk to set the target blur radius // jQuery might not reach the end value setBlur(ele,endRadius); } }); }; // Start tweening toWARDs blurred image window.setTimeout(function() { tweenBlur('.item',10); },1000); // Reverse tweening after 3 seconds window.setTimeout(function() { tweenBlur('.item',10,0); },3000); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="item"> <p>Sample text that will be blurred.</p> <img src="http://placehold.it/500x500" /> </div>
以上是大佬教程为你收集整理的jQuery中的动画css模糊过滤器全部内容,希望文章能够帮你解决jQuery中的动画css模糊过滤器所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。