Skip to content

Instantly share code, notes, and snippets.

@DigitalKrony
Last active November 28, 2018 20:38
Show Gist options
  • Save DigitalKrony/9d2e903997e71c85bacc94aa4d6ed537 to your computer and use it in GitHub Desktop.
Save DigitalKrony/9d2e903997e71c85bacc94aa4d6ed537 to your computer and use it in GitHub Desktop.
// https://gist.github.com/gre/1650294
/*
* Found HERE: https://codepen.io/xerxesnoble/pen/JNgmJR
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
const ease = {
// no easing, no acceleration
linear: function (t) { return t },
// accelerating from zero velocity
InQuad: function (t) { return t*t },
// decelerating to zero velocity
OutQuad: function (t) { return t*(2-t) },
// acceleration until halfway, then deceleration
InOutQuad: function (t) { return t<.5 ? 2*t*t : -1+(4-2*t)*t },
// accelerating from zero velocity
InCubic: function (t) { return t*t*t },
// decelerating to zero velocity
OutCubic: function (t) { return (--t)*t*t+1 },
// acceleration until halfway, then deceleration
InOutCubic: function (t) { return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1 },
// accelerating from zero velocity
InQuart: function (t) { return t*t*t*t },
// decelerating to zero velocity
OutQuart: function (t) { return 1-(--t)*t*t*t },
// acceleration until halfway, then deceleration
InOutQuart: function (t) { return t<.5 ? 8*t*t*t*t : 1-8*(--t)*t*t*t },
// accelerating from zero velocity
InQuint: function (t) { return t*t*t*t*t },
// decelerating to zero velocity
OutQuint: function (t) { return 1+(--t)*t*t*t*t },
// acceleration until halfway, then deceleration
InOutQuint: function (t) { return t<.5 ? 16*t*t*t*t*t : 1+16*(--t)*t*t*t*t },
// elastic bounce effect at the beginning
InElastic: function (t) { return (.04 - .04 / t) * Math.sin(25 * t) + 1 },
// elastic bounce effect at the end
OutElastic: function (t) { return .04 * t / (--t) * Math.sin(25 * t) },
// elastic bounce effect at the beginning and end
InOutElastic: function (t) { return (t -= .5) < 0 ? (.01 + .01 / t) * Math.sin(50 * t) : (.02 - .01 / t) * Math.sin(50 * t) + 1 }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment