JAVASCRIPT   95
jquery easing js
Guest on 17th August 2022 12:28:20 AM


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

Raw Paste

Login or Register to edit or fork this paste. It's free.