Rick
Rick

Reputation: 1

RaphaelJS - Finding a point in a path while animating

Let's say I have an ellipse e that I wanted to animate along path p.

If I began to animate the ellipse, but then decided to stop the animation, is there any way I could restart the animation from it's current point? I haven't been able to find a way to determine the ellipse's current point along a path after stopping the animation.

Here is my animation code (all standard):

e.attr({ rx: 15, ry: 5 }).animateAlong(p, 15000, true, function () {
                    e.attr({ rx: 10, ry: 10 });
                    clicked = false;
                });

Upvotes: 0

Views: 422

Answers (1)

dev
dev

Reputation: 841

How about you define the last points outside using onAnimate?

var lastX = 15, lastY = 5;
e.onAnimation(function() {
    lastX = e.attr('rx');
    lastY = e.attr('ry');
});

e.attr({ rx: lastX, ry: lastY }).animateAlong(p, 15000, true, function () {
    e.attr({ rx: 10, ry: 10 });
    clicked = false;
});

So if you run this code several times, inside a function or whatever, you ellipse will start not at 15, 5 but at the last point in the animation (before it was interrupted).

This what you meant?

Upvotes: 1

Related Questions