jquery.easing.1.2.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * jQuery EasIng v1.1.2 - http://gsgd.co.uk/sandbox/jquery.easIng.php
  3. *
  4. * Uses the built In easIng capabilities added In jQuery 1.1
  5. * to offer multiple easIng options
  6. *
  7. * Copyright (c) 2007 George Smith
  8. * Licensed under the MIT License:
  9. * http://www.opensource.org/licenses/mit-license.php
  10. */
  11. // t: current time, b: begInnIng value, c: change In value, d: duration
  12. jQuery.extend( jQuery.easing,
  13. {
  14. easeInQuad: function (x, t, b, c, d) {
  15. return c*(t/=d)*t + b;
  16. },
  17. easeOutQuad: function (x, t, b, c, d) {
  18. return -c *(t/=d)*(t-2) + b;
  19. },
  20. easeInOutQuad: function (x, t, b, c, d) {
  21. if ((t/=d/2) < 1) return c/2*t*t + b;
  22. return -c/2 * ((--t)*(t-2) - 1) + b;
  23. },
  24. easeInCubic: function (x, t, b, c, d) {
  25. return c*(t/=d)*t*t + b;
  26. },
  27. easeOutCubic: function (x, t, b, c, d) {
  28. return c*((t=t/d-1)*t*t + 1) + b;
  29. },
  30. easeInOutCubic: function (x, t, b, c, d) {
  31. if ((t/=d/2) < 1) return c/2*t*t*t + b;
  32. return c/2*((t-=2)*t*t + 2) + b;
  33. },
  34. easeInQuart: function (x, t, b, c, d) {
  35. return c*(t/=d)*t*t*t + b;
  36. },
  37. easeOutQuart: function (x, t, b, c, d) {
  38. return -c * ((t=t/d-1)*t*t*t - 1) + b;
  39. },
  40. easeInOutQuart: function (x, t, b, c, d) {
  41. if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
  42. return -c/2 * ((t-=2)*t*t*t - 2) + b;
  43. },
  44. easeInQuint: function (x, t, b, c, d) {
  45. return c*(t/=d)*t*t*t*t + b;
  46. },
  47. easeOutQuint: function (x, t, b, c, d) {
  48. return c*((t=t/d-1)*t*t*t*t + 1) + b;
  49. },
  50. easeInOutQuint: function (x, t, b, c, d) {
  51. if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
  52. return c/2*((t-=2)*t*t*t*t + 2) + b;
  53. },
  54. easeInSine: function (x, t, b, c, d) {
  55. return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
  56. },
  57. easeOutSine: function (x, t, b, c, d) {
  58. return c * Math.sin(t/d * (Math.PI/2)) + b;
  59. },
  60. easeInOutSine: function (x, t, b, c, d) {
  61. return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
  62. },
  63. easeInExpo: function (x, t, b, c, d) {
  64. return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
  65. },
  66. easeOutExpo: function (x, t, b, c, d) {
  67. return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
  68. },
  69. easeInOutExpo: function (x, t, b, c, d) {
  70. if (t==0) return b;
  71. if (t==d) return b+c;
  72. if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
  73. return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
  74. },
  75. easeInCirc: function (x, t, b, c, d) {
  76. return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
  77. },
  78. easeOutCirc: function (x, t, b, c, d) {
  79. return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
  80. },
  81. easeInOutCirc: function (x, t, b, c, d) {
  82. if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
  83. return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
  84. },
  85. easeInElastic: function (x, t, b, c, d) {
  86. var s=1.70158;var p=0;var a=c;
  87. if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
  88. if (a < Math.abs(c)) { a=c; var s=p/4; }
  89. else var s = p/(2*Math.PI) * Math.asin (c/a);
  90. return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  91. },
  92. easeOutElastic: function (x, t, b, c, d) {
  93. var s=1.70158;var p=0;var a=c;
  94. if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
  95. if (a < Math.abs(c)) { a=c; var s=p/4; }
  96. else var s = p/(2*Math.PI) * Math.asin (c/a);
  97. return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
  98. },
  99. easeInOutElastic: function (x, t, b, c, d) {
  100. var s=1.70158;var p=0;var a=c;
  101. if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
  102. if (a < Math.abs(c)) { a=c; var s=p/4; }
  103. else var s = p/(2*Math.PI) * Math.asin (c/a);
  104. if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
  105. return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
  106. },
  107. easeInBack: function (x, t, b, c, d, s) {
  108. if (s == undefined) s = 1.70158;
  109. return c*(t/=d)*t*((s+1)*t - s) + b;
  110. },
  111. easeOutBack: function (x, t, b, c, d, s) {
  112. if (s == undefined) s = 1.70158;
  113. return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
  114. },
  115. easeInOutBack: function (x, t, b, c, d, s) {
  116. if (s == undefined) s = 1.70158;
  117. if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
  118. return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
  119. },
  120. easeInBounce: function (x, t, b, c, d) {
  121. return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
  122. },
  123. easeOutBounce: function (x, t, b, c, d) {
  124. if ((t/=d) < (1/2.75)) {
  125. return c*(7.5625*t*t) + b;
  126. } else if (t < (2/2.75)) {
  127. return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
  128. } else if (t < (2.5/2.75)) {
  129. return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
  130. } else {
  131. return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
  132. }
  133. },
  134. easeInOutBounce: function (x, t, b, c, d) {
  135. if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
  136. return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
  137. }
  138. });