Skip to content

Instantly share code, notes, and snippets.

@purag
Last active March 18, 2019 17:29
Show Gist options
  • Save purag/0bdb9c25d7c6c5ae45600b69049b9f67 to your computer and use it in GitHub Desktop.
Save purag/0bdb9c25d7c6c5ae45600b69049b9f67 to your computer and use it in GitHub Desktop.
A collection of simple easing functions for JavaScript
let easing = {
// classic linear
linear: t => t,
// slow -> fast
easeInQuad: t => t*t,
easeInCubic: t => t*t*t,
easeInQuint: t => t*t*t*t,
// fast -> slow
easeOutQuad: t => 1 - easing.easeInQuad(1 - t),
easeOutCubic: t => 1 - easing.easeInCubic(1 - t),
easeOutQuint: t => 1 - easing.easeInQuint(1 - t),
// slow -> fast -> slow
easeInOutQuad: t => t < .5 ? easing.easeInQuad(t * 2) / 2 : 1 - easing.easeInQuad((1 - t) * 2) / 2,
easeInOutCubic: t => t < .5 ? easing.easeInCubic(t * 2) / 2 : 1 - easing.easeInCubic((1 - t) * 2) / 2,
easeInOutQuint: t => t < .5 ? easing.easeInQuint(t * 2) / 2 : 1 - easing.easeInQuint((1 - t) * 2) / 2,
// bounce
easeOutElastic: t => Math.pow(2, -10 * t) * Math.sin((t - 0.3 / 4) * (2 * Math.PI) / 0.3) + 1
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment