Advertisement
Romul81

ease functions

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