jquery.easing.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * jQuery Easing
  3. */
  4. $.extend($.easing,
  5. {
  6. def: 'easeOutQuad',
  7. swing: function (x, t, b, c, d) {
  8. return $.easing[$.easing.def](x, t, b, c, d);
  9. },
  10. easeInQuad: function (x, t, b, c, d) {
  11. return c*(t/=d)*t + b;
  12. },
  13. easeOutQuad: function (x, t, b, c, d) {
  14. return -c *(t/=d)*(t-2) + b;
  15. },
  16. easeInOutQuad: function (x, t, b, c, d) {
  17. if ((t/=d/2) < 1) return c/2*t*t + b;
  18. return -c/2 * ((--t)*(t-2) - 1) + b;
  19. },
  20. easeInCubic: function (x, t, b, c, d) {
  21. return c*(t/=d)*t*t + b;
  22. },
  23. easeOutCubic: function (x, t, b, c, d) {
  24. return c*((t=t/d-1)*t*t + 1) + b;
  25. },
  26. easeInOutCubic: function (x, t, b, c, d) {
  27. if ((t/=d/2) < 1) return c/2*t*t*t + b;
  28. return c/2*((t-=2)*t*t + 2) + b;
  29. },
  30. easeInQuart: function (x, t, b, c, d) {
  31. return c*(t/=d)*t*t*t + b;
  32. },
  33. easeOutQuart: function (x, t, b, c, d) {
  34. return -c * ((t=t/d-1)*t*t*t - 1) + b;
  35. },
  36. easeInOutQuart: function (x, t, b, c, d) {
  37. if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
  38. return -c/2 * ((t-=2)*t*t*t - 2) + b;
  39. },
  40. easeInQuint: function (x, t, b, c, d) {
  41. return c*(t/=d)*t*t*t*t + b;
  42. },
  43. easeOutQuint: function (x, t, b, c, d) {
  44. return c*((t=t/d-1)*t*t*t*t + 1) + b;
  45. },
  46. easeInOutQuint: function (x, t, b, c, d) {
  47. if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
  48. return c/2*((t-=2)*t*t*t*t + 2) + b;
  49. },
  50. easeInSine: function (x, t, b, c, d) {
  51. return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
  52. },
  53. easeOutSine: function (x, t, b, c, d) {
  54. return c * Math.sin(t/d * (Math.PI/2)) + b;
  55. },
  56. easeInOutSine: function (x, t, b, c, d) {
  57. return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
  58. },
  59. easeInExpo: function (x, t, b, c, d) {
  60. return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
  61. },
  62. easeOutExpo: function (x, t, b, c, d) {
  63. return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
  64. },
  65. easeInOutExpo: function (x, t, b, c, d) {
  66. if (t==0) return b;
  67. if (t==d) return b+c;
  68. if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
  69. return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
  70. },
  71. easeInCirc: function (x, t, b, c, d) {
  72. return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
  73. },
  74. easeOutCirc: function (x, t, b, c, d) {
  75. return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
  76. },
  77. easeInOutCirc: function (x, t, b, c, d) {
  78. if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
  79. return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
  80. },
  81. easeInElastic: function (x, t, b, c, d) {
  82. var s=1.70158;var p=0;var a=c;
  83. if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
  84. if (a < Math.abs(c)) { a=c; var s=p/4; }
  85. else var s = p/(2*Math.PI) * Math.asin (c/a);
  86. return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  87. },
  88. easeOutElastic: function (x, t, b, c, d) {
  89. var s=1.70158;var p=0;var a=c;
  90. if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
  91. if (a < Math.abs(c)) { a=c; var s=p/4; }
  92. else var s = p/(2*Math.PI) * Math.asin (c/a);
  93. return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
  94. },
  95. easeInOutElastic: function (x, t, b, c, d) {
  96. var s=1.70158;var p=0;var a=c;
  97. if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
  98. if (a < Math.abs(c)) { a=c; var s=p/4; }
  99. else var s = p/(2*Math.PI) * Math.asin (c/a);
  100. if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  101. return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
  102. },
  103. easeInBack: function (x, t, b, c, d, s) {
  104. if (s == undefined) s = 1.70158;
  105. return c*(t/=d)*t*((s+1)*t - s) + b;
  106. },
  107. easeOutBack: function (x, t, b, c, d, s) {
  108. if (s == undefined) s = 1.70158;
  109. return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
  110. },
  111. easeInOutBack: function (x, t, b, c, d, s) {
  112. if (s == undefined) s = 1.70158;
  113. if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
  114. return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
  115. },
  116. easeInBounce: function (x, t, b, c, d) {
  117. return c - $.easing.easeOutBounce (x, d-t, 0, c, d) + b;
  118. },
  119. easeOutBounce: function (x, t, b, c, d) {
  120. if ((t/=d) < (1/2.75)) {
  121. return c*(7.5625*t*t) + b;
  122. } else if (t < (2/2.75)) {
  123. return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
  124. } else if (t < (2.5/2.75)) {
  125. return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
  126. } else {
  127. return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
  128. }
  129. },
  130. easeInOutBounce: function (x, t, b, c, d) {
  131. if (t < d/2) return $.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
  132. return $.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
  133. }
  134. });