class Reactive · Animation

RvgAnimation

A running animation: returned by every animator call (eased, follow, morph, set, morphAll, …) to stop it or to wait for it.

An animation of many objects (morphAll, easedAll, followAll) is one handle for all of them: it is done when the last one is done, and cancel stops all. An animation counts as cancelled (not completed) when cancel or Animate.cancel stops it, or when a new animation of the same object replaces it.

Properties

donereadonly

done: Promise<boolean>

A promise that resolves when the animation has finished: with true if it completed, false if it was cancelled.

await anim.done waits for the animation (for many objects: for the last one). It never rejects, also not when the animation is cancelled; check the result if that matters. onComplete still works. Like every promise it resolves asynchronously: after the code that cancelled the animation (for example, code that started a new animation of the same object) has run. To react at once, use whenDone, which is called synchronously when the animation completes or is cancelled.

runningreadonly

running: boolean

True while the animation runs; false once it has completed or was cancelled.

Methods

cancel

cancel(): void

Stops the animation where it is (for many objects: all of them). Nothing happens if it has finished already; onComplete is not called.

whenDone

whenDone(callback: (completed: boolean) => void): void

Calls callback once when the animation has finished: with true if it completed, false if it was cancelled. It is called synchronously: on cancel (or a replacing animation) before that call returns, and at once if the animation has finished already.

callback
The function to call; its argument says whether the animation completed.