chrisbateman / impetus

Agnostic utility for adding momentum to anything. It's like iScroll, except not for scrolling. Supports mouse and touch events.
chrisbateman.github.io/impetus
MIT License
487 stars 70 forks source link

Exposes previous X and previous Y in callback #43

Open romellem opened 6 years ago

romellem commented 6 years ago

In my case, I didn't just want absolute X and Y values, but wanted to see how those X and Y values had changed since the last callback.

By exposing the previous X and Y values in our callback via two new arguments, I can now calculate these deltas. For example:

new Impetus({
    source: '#some-element',
    update: function(x, y, px, py) {
        console.log('x ', x);
        console.log('y ', y);
        console.log('previous x ', px);
        console.log('previous y ', py);
        console.log('change in x ', x - px);
        console.log('change in y ', y - py);
    }
});

I've also included the commits from #41 (Fix memory leaks) since those proved to be a fairly useful addition to the codebase.