Last active
August 29, 2015 14:07
-
-
Save vonWolfehaus/c5ff03d78b19d9aea793 to your computer and use it in GitHub Desktop.
Dampen a value to ease it to a target value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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