jQuery Easing 使用方法及其图解

Time:2014/10/07 09:42:45   Click:

从jQuery API 文档中可以知道,jQuery自界说动画的函数.animate( properties [, duration] [, easing] [, complete] )有四个参数:

  • properties:一组包括作为动画属性以及终值的样式属性以及及其值的纠合
  • duration(可选):动画执行时间,其值可所以三种预定速率之一的字符串("slow", "normal", or "fast")或者暗示动画时长的毫秒数值(如:1000)
  • easing(可选):要使用的过渡效果的名称,如:"linear" 或者"swing"
  • complete(可选):在动画完成时执行的函数
此中参数easing默许有两个效果:"linear"以及"swing",若是必要更多效果就要插件支撑了,jQuery Easing Plugin提供了像"easeOutExpo"、"easeOutBounce"等30多种效果,年夜家可以点击这里去看每一一种easing的演示效果,下面具体先容下其使用方式及每一种easing的曲线图。

jQuery easing 使用方式

起首,项目中若是必要使用特殊的动画效果,则必要在引入jQuery以后引入jquery.easing.1.3.js
[html]view plaincopyprint?
  1. <scripttype="text/javascript"src="http://code.jquery.com/jquery-1.8.3.js"></script>
  2. <scripttype="text/javascript"src="http://gsgd.co.uk/sandbox/jquery/easing/jquery.easing.1.3.js"></script>

引入以后,easing参数可选的值就有如下32种:

  1. linear
  2. swing
  3. easeInQuad
  4. easeOutQuad
  5. easeInOutQuad
  6. easeInCubic
  7. easeOutCubic
  8. easeInOutCubic
  9. easeInQuart
  10. easeOutQuart
  11. easeInOutQuart
  12. easeInQuint
  13. easeOutQuint
  14. easeInOutQuint
  15. easeInExpo
  16. easeOutExpo
  17. easeInOutExpo
  18. easeInSine
  19. easeOutSine
  20. easeInOutSine
  21. easeInCirc
  22. easeOutCirc
  23. easeInOutCirc
  24. easeInElastic
  25. easeOutElastic
  26. easeInOutElastic
  27. easeInBack
  28. easeOutBack
  29. easeInOutBack
  30. easeInBounce
  31. easeOutBounce
  32. easeInOutBounce
固然一般一个项目中不成能会用到这么多效果,为了削减代码冗余,需要时可以不消引入整个jquery.easing.1.3.js,咱们可以只把咱们必要的几种easing放入Javascript文件中,如项目中只用到"easeOutExpo"以及"easeOutBounce"两种效果,只必要下面的代码就能够了
[javascript]view plaincopyprint?
  1. jQuery.extend( jQuery.easing,  
  2. {  
  3.     easeOutExpo: function (x, t, b, c, d) {  
  4. return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;  
  5.     },  
  6.     easeOutBounce: function (x, t, b, c, d) {  
  7. if ((t/=d) < (1/2.75)) {  
  8. return c*(7.5625*t*t) + b;  
  9.         } elseif (t < (2/2.75)) {  
  10. return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;  
  11.         } elseif (t < (2.5/2.75)) {  
  12. return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;  
  13.         } else {  
  14. return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;  
  15.         }  
  16.     },  
  17. });  

使用jQuery自界说动画函数animate来指定easing效果,如自界说一种类弹簧效果的动画:

[javascript]view plaincopyprint?
  1. $(myElement).animate({  
  2.     top: 500,  
  3.     opacity: 1  
  4. }, 1000, 'easeOutBounce');  

值患上一提的是jQuery 1.4版本中对animate()方式,easing的方式进行了扩大,支撑为每一个属性指定easing方式,具体请参考这里,如:

[javascript]view plaincopyprint?
  1. $(myElement).animate({  
  2.     left: [500, 'swing'],  
  3.     top: [200, 'easeOutBounce']  
  4. });  
也能够用另一种写法:
[javascript]view plaincopyprint?
  1. $(myElement).animate({  
  2.     left: 500,  
  3.     top: 200  
  4. }, {  
  5.     specialEasing: {  
  6.         left: 'swing',  
  7.         top: 'easeOutBounce'
  8.     }  
  9. });  

使用jQuery内置动画函数如slideUp()、slideDown()等来指定easing效果,如下两种方式均可以:
[javascript]view plaincopyprint?
  1. $(myElement).slideUp(1000, method, callback});  
  2. $(myElement).slideUp({  
  3.     duration: 1000,   
  4.     easing: method,   
  5.     complete: callback  
  6. });  


jQuery easing 图解

如下图解可让你更易理解每一一种easing的效果

1. linear 2. swing 3. easeInQuad 4. easeOutQuad 5. easeInOutQuad 6. easeInCubic
7. easeOutCubic 8. easeInOutCubic 9. easeInQuart 10. easeOutQuart 11. easeInOutQuart 12. easeInQuint
13. easeOutQuint 14. easeInOutQuint 15. easeInExpo 16. easeOutExpo 17. easeInOutExpo 18. easeInSine
19. easeOutSine 20. easeInOutSine 21. easeInCirc 22. easeOutCirc 23. easeInOutCirc 24. easeInElastic
25. easeOutElastic 26. easeInOutElastic 27. easeInBack 28. easeOutBack 29. easeInOutBack 30. easeInBounce




31. easeOutBounce 32. easeInOutBounce  

     尚狐网络-致力于为四川成都提供最专业的网站建设服务。

TAG
TOP

四川尚狐网络@2012 版权所有
蜀ICP备12016524号-2

立即咨询
成都网站建设,成都做网站,四川尚狐网络
40f13d50b73e104f832ed1b719ae6935