API Reference
This document provides a detailed reference for the public API of tween.js.
Main Exports
These functions are exported from the main package entry point.
update(time?: number, preserve?: boolean): void
Updates all tweens in the main group. time is the current time in milliseconds. If not provided, performance.now() is used. preserve is a deprecated parameter.
getAll(): Tween[]
Returns an array of all tweens in the main group.
removeAll(): void
Removes all tweens from the main group.
add(tween: Tween): void
Adds a tween to the main group.
remove(tween: Tween): void
Removes a tween from the main group.
Tween<T> Class
The core class for creating an animation.
constructor(object: T, group?: Group | true)
Creates a new tween.
* object: The object whose properties you want to animate.
* group: An optional Group instance to add this tween to. Passing true adds it to the default main group (deprecated).
.to(target: object, duration?: number): this
Defines the target state of the animation.
* target: An object with the final properties and values.
* duration: The duration of the animation in milliseconds (default: 1000).
.start(time?: number, overrideStartingValues?: boolean): this
Starts the tween.
* time: The start time in milliseconds. Defaults to the current time.
* overrideStartingValues: If true, the tween will start from the current values of the object, not from the values at creation time.
.startFromCurrentValues(time?: number): this
Alias for .start(time, true).
.stop(): this
Stops the tween. The onStop callback is fired.
.end(): this
Immediately stops the tween and sets the object's properties to their final values. The onComplete callback is fired.
.pause(time?: number): this
Pauses the tween. The animation can be resumed with .resume().
.resume(time?: number): this
Resumes a paused tween.
.stopChainedTweens(): this
Stops all tweens that were chained from this tween.
.chain(...tweens: Tween[]): this
Chains one or more tweens to start after this one completes.
.delay(amount: number): this
Sets a delay in milliseconds before the tween starts.
.repeat(times: number): this
Sets the number of times the tween should repeat after the first run. Use Infinity for endless repetition.
.repeatDelay(amount: number): this
Sets a delay in milliseconds between repetitions.
.yoyo(yoyo: boolean): this
If true, the tween will reverse direction on every repetition. Requires .repeat() to be set.
.easing(easingFunction: Function): this
Specifies the easing function to use. See the Easing object below.
.interpolation(interpolationFunction: Function): this
Specifies the interpolation algorithm for array-based animations. See the Interpolation object.
.onStart(callback: (object: T) => void): this
Sets a callback that fires once when the tween begins (after any delay).
.onEveryStart(callback: (object: T) => void): this
Sets a callback that fires every time the tween begins (including repeats).
.onUpdate(callback: (object: T, elapsed: number) => void): this
Sets a callback that fires on every animation frame.
.onRepeat(callback: (object: T) => void): this
Sets a callback that fires when a repetition starts.
.onComplete(callback: (object: T) => void): this
Sets a callback that fires when the tween completes normally.
.onStop(callback: (object: T) => void): this
Sets a callback that fires when the tween is explicitly stopped.
Group Class
A class for managing a collection of tweens.
constructor(...tweens: Tween[])
Creates a new group and optionally adds initial tweens.
.getAll(): Tween[]
Returns an array of all tweens in this group.
.removeAll(): void
Removes all tweens from this group.
.add(tween: Tween): void
Adds a tween to this group.
.remove(tween: Tween): void
Removes a tween from this group.
.update(time?: number): void
Updates all tweens within this group.
Easing Object
A collection of built-in easing functions.
Easing.Linear.NoneEasing.Quadratic.In,Easing.Quadratic.Out,Easing.Quadratic.InOutEasing.Cubic.In,Easing.Cubic.Out,Easing.Cubic.InOutEasing.Quartic.In,Easing.Quartic.Out,Easing.Quartic.InOutEasing.Quintic.In,Easing.Quintic.Out,Easing.Quintic.InOutEasing.Sinusoidal.In,Easing.Sinusoidal.Out,Easing.Sinusoidal.InOutEasing.Exponential.In,Easing.Exponential.Out,Easing.Exponential.InOutEasing.Circular.In,Easing.Circular.Out,Easing.Circular.InOutEasing.Elastic.In,Easing.Elastic.Out,Easing.Elastic.InOutEasing.Back.In,Easing.Back.Out,Easing.Back.InOutEasing.Bounce.In,Easing.Bounce.Out,Easing.Bounce.InOut
Interpolation Object
A collection of algorithms for array interpolation.
Interpolation.LinearInterpolation.BezierInterpolation.CatmullRom