Search code examples
javascriptperformanceoptimizationtween

JS tween how to improve?


Im trying to make a simple expo tween, it works, but its a bit jittery and FF seems to hang a bit. What can I do to improve it?

var distance = (target - x) * dir;

x += (distance / 5) * dir;

if (dir == 1 && x >= target-1) {
    return;
    }

if (dir == -1 && x <= target+1) {
     return;
    }

Solution

  • You'll probably find your answer and more looking at the source of tween.js

    All tween curves visualized: http://sole.github.com/tween.js/examples/03_graphs.html