Skip to content

Instantly share code, notes, and snippets.

@daveyjones
Last active May 1, 2021 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveyjones/5ce5bab5b37053ee73842fa0f83edcc1 to your computer and use it in GitHub Desktop.
Save daveyjones/5ce5bab5b37053ee73842fa0f83edcc1 to your computer and use it in GitHub Desktop.
JavaScript Easing Functions
// Source: https://github.com/danro/jquery-easing/blob/master/jquery.easing.js
// t: current time
// b: beginning value
// c: change in value
// d: duration
ease_in_cubic(t, b, c, d) {
return c*(t/=d)*t*t + b;
}
ease_in_quad(t, b, c, d) {
return c*(t/=d)*t + b;
}
function ease_in_out_cubic(t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t*t + b;
return c/2*((t-=2)*t*t + 2) + b;
}
function ease_in_out_sine(t, b, c, d) {
return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
}
function ease_out_cubic(t, b, c, d) {
return c*((t=t/d-1)*t*t + 1) + b;
}
function ease_out_elastic(t, b, c, d) {
var s=1.70158;var p=0;var a=c;
if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
if (a < Math.abs(c)) { a=c; var s=p/4; }
else var s = p/(2*Math.PI) * Math.asin (c/a);
if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
}
function ease_out_quad(t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
}
function ease_out_sine(t, b, c, d) {
return c * Math.sin(t/d * (Math.PI/2)) + b;
}
function ease_in_expo(t, b, c, d) {
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
}
function ease_out_expo(t, b, c, d) {
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment