jQuery插件:螺旋动画

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jQuery插件:螺旋动画相关的知识,希望对你有一定的参考价值。

A jQuery plugin that adds the .spiral() method, wich moves an element along an archimedean spiral path.
  1. /*
  2.  * Spiral [v1.1]
  3.  * Distributed under the Do-wathever-the-hell-you-want-with-it License
  4.  *
  5.  * Web site: http://claudiobonifazi.com
  6.  * Blog: http://claudiobonifazi.com?p=4
  7.  * Twitter: @ClaudioBonifazi
  8.  */
  9.  
  10.  
  11.  
  12. /*
  13. Options = {
  14. Radius: numeric (pixels), horizontal distance between starting and final points;
  15. Duration: number of milliseconds (as for animate) ;
  16. Easing: the number of cicles - if it is higher than 2 it will make more turns and will assume a 'bouncing' deceleration effect
  17. Queue: boolean (as for animate) ;
  18. Ydirection: boolean. If true, the rotation starts going up instead of down.
  19. Xdirection: boolean. If true the movement will be from left to the right, instead of right to left.
  20. InsideOut: boolean. If true, the object will whirl out from the inside of the spiral. Note that setting it to true changes the sense of Xdirection ;
  21. },
  22. Callback = function called when the animation ends (as for animate) ;
  23. */
  24. (function($){
  25. $.fn.spiral = function( Options, Callback ){
  26. /*-- Input filtering --*/
  27. Opt= {
  28. Radius: 150,
  29. Duration: 100,
  30. Easing: 2,
  31. Queue: false,
  32. Xdirection: false,
  33. Ydirection: false,
  34. InsideOut: false
  35. }
  36. $.extend(Opt,Options)
  37. if(!Callback)
  38. Callback= function(){return};
  39. /*-- Animation starts --*/
  40. return this.each(function(){
  41. var elem=$(this),
  42. start_l=parseInt(elem.css('margin-left')),
  43. start_t=parseInt(elem.css('margin-top')),
  44. start_z=elem.css('z-index');
  45. elem
  46. .animate({'z-index':start_z},{
  47. duration: Opt.Duration,
  48. complete: Callback,
  49. step:function(now,fx){
  50. fgamma = Opt.InsideOut ? Opt.Radius*(1+fx.pos) : Opt.Radius*(1-fx.pos);
  51. gamma=fx.pos*Opt.Easing*Math.PI;
  52. gamma=(Opt.Ydirection) ? -gamma : gamma;
  53. x=(Opt.Xdirection) ? (start_l+Opt.Radius-fgamma*Math.cos(gamma))+'px' : (start_l-Opt.Radius+fgamma*Math.cos(gamma))+'px';
  54. y=(start_t+fgamma*Math.sin(gamma))+'px';
  55. $(fx.elem).css({'margin-left':x,'margin-top':y})
  56. },
  57. queue: Opt.Queue
  58. })
  59. })
  60. }
  61. })(jQuery)

以上是关于jQuery插件:螺旋动画的主要内容,如果未能解决你的问题,请参考以下文章

HTML5粒子螺旋线条3D动画

jQuery 将 div 切片成动画片段

十条jQuery代码片段助力Web开发效率提升

十条jQuery代码片段助力Web开发效率提升

人人必知的10个jQuery小技巧

25个可遇不可求的jQuery插件