Skip to content

Instantly share code, notes, and snippets.

@vonWolfehaus
Last active August 29, 2015 14:07
Show Gist options
  • Save vonWolfehaus/c5ff03d78b19d9aea793 to your computer and use it in GitHub Desktop.
Save vonWolfehaus/c5ff03d78b19d9aea793 to your computer and use it in GitHub Desktop.
Dampen a value to ease it to a target value
var damper = 0.5; // lower is slower
function ease(current, target) {
current += (target - current) * damper;
// fix Zeno's paradox: value is snapped if we're within fraction of a distance unit (usually a pixel)
if (Math.abs(target - current) < 1) {
current = target;
}
return current;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment