easing.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /**
  2. * Kity Animate Easing modified from jQuery Easing
  3. * Author: techird
  4. * Changes:
  5. * 1. make easing functions standalone
  6. * 2. remove the 'x' parameter
  7. */
  8. /* ============================================================
  9. * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
  10. *
  11. * Open source under the BSD License.
  12. *
  13. * Copyright © 2008 George McGinley Smith
  14. * All rights reserved.
  15. * https://raw.github.com/danro/jquery-easing/master/LICENSE
  16. * ======================================================== */
  17. define(function(require, exports, module) {
  18. var easings = {
  19. // t: current_time, b: begin_value, c: change_value, d: duration
  20. linear: function(t, b, c, d) {
  21. return c * (t / d) + b;
  22. },
  23. swing: function(t, b, c, d) {
  24. return easings.easeOutQuad(t, b, c, d);
  25. },
  26. ease: function(t, b, c, d) {
  27. return easings.easeInOutCubic(t, b, c, d);
  28. },
  29. easeInQuad: function(t, b, c, d) {
  30. return c * (t /= d) * t + b;
  31. },
  32. easeOutQuad: function(t, b, c, d) {
  33. return -c * (t /= d) * (t - 2) + b;
  34. },
  35. easeInOutQuad: function(t, b, c, d) {
  36. if ((t /= d / 2) < 1) return c / 2 * t * t + b;
  37. return -c / 2 * ((--t) * (t - 2) - 1) + b;
  38. },
  39. easeInCubic: function(t, b, c, d) {
  40. return c * (t /= d) * t * t + b;
  41. },
  42. easeOutCubic: function(t, b, c, d) {
  43. return c * ((t = t / d - 1) * t * t + 1) + b;
  44. },
  45. easeInOutCubic: function(t, b, c, d) {
  46. if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
  47. return c / 2 * ((t -= 2) * t * t + 2) + b;
  48. },
  49. easeInQuart: function(t, b, c, d) {
  50. return c * (t /= d) * t * t * t + b;
  51. },
  52. easeOutQuart: function(t, b, c, d) {
  53. return -c * ((t = t / d - 1) * t * t * t - 1) + b;
  54. },
  55. easeInOutQuart: function(t, b, c, d) {
  56. if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
  57. return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
  58. },
  59. easeInQuint: function(t, b, c, d) {
  60. return c * (t /= d) * t * t * t * t + b;
  61. },
  62. easeOutQuint: function(t, b, c, d) {
  63. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  64. },
  65. easeInOutQuint: function(t, b, c, d) {
  66. if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
  67. return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
  68. },
  69. easeInSine: function(t, b, c, d) {
  70. return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
  71. },
  72. easeOutSine: function(t, b, c, d) {
  73. return c * Math.sin(t / d * (Math.PI / 2)) + b;
  74. },
  75. easeInOutSine: function(t, b, c, d) {
  76. return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
  77. },
  78. easeInExpo: function(t, b, c, d) {
  79. return (t === 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
  80. },
  81. easeOutExpo: function(t, b, c, d) {
  82. return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
  83. },
  84. easeInOutExpo: function(t, b, c, d) {
  85. if (t === 0) return b;
  86. if (t == d) return b + c;
  87. if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
  88. return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
  89. },
  90. easeInCirc: function(t, b, c, d) {
  91. return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
  92. },
  93. easeOutCirc: function(t, b, c, d) {
  94. return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
  95. },
  96. easeInOutCirc: function(t, b, c, d) {
  97. if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
  98. return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
  99. },
  100. easeInElastic: function(t, b, c, d) {
  101. var s = 1.70158;
  102. var p = 0;
  103. var a = c;
  104. if (t === 0) return b;
  105. if ((t /= d) == 1) return b + c;
  106. if (!p) p = d * 0.3;
  107. if (a < Math.abs(c)) {
  108. a = c;
  109. s = p / 4;
  110. } else s = p / (2 * Math.PI) * Math.asin(c / a);
  111. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  112. },
  113. easeOutElastic: function(t, b, c, d) {
  114. var s = 1.70158;
  115. var p = 0;
  116. var a = c;
  117. if (t === 0) return b;
  118. if ((t /= d) == 1) return b + c;
  119. if (!p) p = d * 0.3;
  120. if (a < Math.abs(c)) {
  121. a = c;
  122. s = p / 4;
  123. } else s = p / (2 * Math.PI) * Math.asin(c / a);
  124. return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
  125. },
  126. easeInOutElastic: function(t, b, c, d) {
  127. var s = 1.70158;
  128. var p = 0;
  129. var a = c;
  130. if (t === 0) return b;
  131. if ((t /= d / 2) == 2) return b + c;
  132. if (!p) p = d * (0.3 * 1.5);
  133. if (a < Math.abs(c)) {
  134. a = c;
  135. var s = p / 4;
  136. } else var s = p / (2 * Math.PI) * Math.asin(c / a);
  137. if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  138. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
  139. },
  140. easeInBack: function(t, b, c, d, s) {
  141. if (s == undefined) s = 1.70158;
  142. return c * (t /= d) * t * ((s + 1) * t - s) + b;
  143. },
  144. easeOutBack: function(t, b, c, d, s) {
  145. if (s == undefined) s = 1.70158;
  146. return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
  147. },
  148. easeInOutBack: function(t, b, c, d, s) {
  149. if (s == undefined) s = 1.70158;
  150. if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
  151. return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
  152. },
  153. easeInBounce: function(t, b, c, d) {
  154. return c - easings.easeOutBounce(d - t, 0, c, d) + b;
  155. },
  156. easeOutBounce: function(t, b, c, d) {
  157. if ((t /= d) < (1 / 2.75)) {
  158. return c * (7.5625 * t * t) + b;
  159. } else if (t < (2 / 2.75)) {
  160. return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
  161. } else if (t < (2.5 / 2.75)) {
  162. return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
  163. } else {
  164. return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
  165. }
  166. },
  167. easeInOutBounce: function(t, b, c, d) {
  168. if (t < d / 2) return easings.easeInBounce(t * 2, 0, c, d) * .5 + b;
  169. return easings.easeOutBounce(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
  170. }
  171. };
  172. return easings;
  173. });
  174. /*
  175. *
  176. * TERMS OF USE - EASING EQUATIONS
  177. *
  178. * Open source under the BSD License.
  179. *
  180. * Copyright © 2001 Robert Penner
  181. * All rights reserved.
  182. *
  183. * Redistribution and use in source and binary forms, with or without modification,
  184. * are permitted provided that the following conditions are met:
  185. *
  186. * Redistributions of source code must retain the above copyright notice, this list of
  187. * conditions and the following disclaimer.
  188. * Redistributions in binary form must reproduce the above copyright notice, this list
  189. * of conditions and the following disclaimer in the documentation and/or other materials
  190. * provided with the distribution.
  191. *
  192. * Neither the name of the author nor the names of contributors may be used to endorse
  193. * or promote products derived from this software without specific prior written permission.
  194. *
  195. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  196. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  197. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  198. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  199. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  200. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  201. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  202. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  203. * OF THE POSSIBILITY OF SUCH DAMAGE.
  204. *
  205. */