Skip to content

@ue-too/animate / index / Animation

Class: Animation<T> ​

Defined in: composite-animation.ts:740

Keyframe-based animation for a single value.

Remarks ​

The Animation class interpolates a value through a series of keyframes over time. It handles:

  • Keyframe interpolation with binary search for efficiency
  • Easing functions for smooth motion curves
  • Reverse playback
  • Looping with optional max loop count
  • Delays before start and drag time after completion
  • Lifecycle callbacks

How It Works ​

  1. Define keyframes at percentages (0.0 to 1.0) along the timeline
  2. Provide a callback to apply the animated value
  3. Provide an interpolation helper for the value type
  4. Call animate(deltaTime) each frame to progress the animation

Example ​

Animating a number with easing

typescript
let opacity = 0;

const fadeIn = new Animation(
  [
    { percentage: 0, value: 0 },
    { percentage: 1, value: 1, easingFn: (t) => t * t } // Ease-in
  ],
  (value) => { opacity = value; },
  numberHelperFunctions,
  1000 // 1 second duration
);

fadeIn.start();

// In animation loop
function loop(deltaTime: number) {
  fadeIn.animate(deltaTime);
  element.style.opacity = opacity;
}

Type Parameters ​

T ​

T

The type of value being animated

Implements ​

Constructors ​

Constructor ​

new Animation<T>(keyFrames, applyAnimationValue, animatableAttributeHelper, duration, loop, parent, setUpFn, tearDownFn, easeFn): Animation<T>

Defined in: composite-animation.ts:766

Parameters ​

keyFrames ​

Keyframe<T>[]

applyAnimationValue ​

(value) => void

animatableAttributeHelper ​

AnimatableAttributeHelper<T>

duration ​

number = 1000

loop ​

boolean = false

parent ​

AnimatorContainer | undefined

setUpFn ​

Function = ...

tearDownFn ​

Function = ...

easeFn ​

(percentage) => number

Returns ​

Animation<T>

Accessors ​

delay ​

Get Signature ​

get delay(): number

Defined in: composite-animation.ts:1102

Returns ​

number

Set Signature ​

set delay(delayTime): void

Defined in: composite-animation.ts:1106

Parameters ​
delayTime ​

number

Returns ​

void

Implementation of ​

Animator.delay


drag ​

Get Signature ​

get drag(): number

Defined in: composite-animation.ts:1113

Returns ​

number

Set Signature ​

set drag(dragTime): void

Defined in: composite-animation.ts:1117

Parameters ​
dragTime ​

number

Returns ​

void

Implementation of ​

Animator.drag


duration ​

Get Signature ​

get duration(): number

Defined in: composite-animation.ts:1054

Returns ​

number

Set Signature ​

set duration(duration): void

Defined in: composite-animation.ts:1058

Parameters ​
duration ​

number

Returns ​

void

Implementation of ​

Animator.duration


easeFunction ​

Get Signature ​

get easeFunction(): (percentage) => number

Defined in: composite-animation.ts:1156

Returns ​

(percentage): number

Parameters ​
percentage ​

number

Returns ​

number

Set Signature ​

set easeFunction(easeFn): void

Defined in: composite-animation.ts:1160

Parameters ​
easeFn ​

(percentage) => number

Returns ​

void


keyFrames ​

Get Signature ​

get keyFrames(): Keyframe<T>[]

Defined in: composite-animation.ts:1152

Returns ​

Keyframe<T>[]

Set Signature ​

set keyFrames(keyFrames): void

Defined in: composite-animation.ts:1143

Parameters ​
keyFrames ​

Keyframe<T>[]

Returns ​

void


loops ​

Get Signature ​

get loops(): boolean

Defined in: composite-animation.ts:1046

Returns ​

boolean

Set Signature ​

set loops(loop): void

Defined in: composite-animation.ts:1050

Parameters ​
loop ​

boolean

Returns ​

void

Implementation of ​

Animator.loops


maxLoopCount ​

Get Signature ​

get maxLoopCount(): number | undefined

Defined in: composite-animation.ts:1196

Returns ​

number | undefined

Set Signature ​

set maxLoopCount(maxLoopCount): void

Defined in: composite-animation.ts:1200

Parameters ​
maxLoopCount ​

number | undefined

Returns ​

void

Implementation of ​

Animator.maxLoopCount


playing ​

Get Signature ​

get playing(): boolean

Defined in: composite-animation.ts:824

Returns ​

boolean

Implementation of ​

Animator.playing


trueDuration ​

Get Signature ​

get trueDuration(): number

Defined in: composite-animation.ts:1124

Returns ​

number

Set Signature ​

set trueDuration(duration): void

Defined in: composite-animation.ts:1128

Parameters ​
duration ​

number

Returns ​

void

Methods ​

animate() ​

animate(deltaTime): void

Defined in: composite-animation.ts:828

Parameters ​

deltaTime ​

number

Returns ​

void

Implementation of ​

Animator.animate


clearOnEnd() ​

clearOnEnd(): void

Defined in: composite-animation.ts:1188

Returns ​

void

Implementation of ​

Animator.clearOnEnd


clearOnStart() ​

clearOnStart(): void

Defined in: composite-animation.ts:1192

Returns ​

void

Implementation of ​

Animator.clearOnStart


detachParent() ​

detachParent(): void

Defined in: composite-animation.ts:1139

Returns ​

void

Implementation of ​

Animator.detachParent


findValue() ​

findValue(valuePercentage, keyframes, animatableAttributeHelper): T

Defined in: composite-animation.ts:957

Parameters ​

valuePercentage ​

number

keyframes ​

Keyframe<T>[]

animatableAttributeHelper ​

AnimatableAttributeHelper<T>

Returns ​

T


nonCascadingDuration() ​

nonCascadingDuration(newDuration): void

Defined in: composite-animation.ts:1075

Parameters ​

newDuration ​

number

Returns ​

void

Implementation of ​

Animator.nonCascadingDuration


onEnd() ​

onEnd(callback): UnSubscribe

Defined in: composite-animation.ts:1164

Parameters ​

callback ​

Function

Returns ​

UnSubscribe

Implementation of ​

Animator.onEnd


onStart() ​

onStart(callback): UnSubscribe

Defined in: composite-animation.ts:1171

Parameters ​

callback ​

Function

Returns ​

UnSubscribe

Implementation of ​

Animator.onStart


onStartAfterDelay() ​

onStartAfterDelay(callback): UnSubscribe

Defined in: composite-animation.ts:1180

Parameters ​

callback ​

Function

Returns ​

UnSubscribe


pause() ​

pause(): void

Defined in: composite-animation.ts:816

Returns ​

void

Implementation of ​

Animator.pause


resetAnimationState() ​

resetAnimationState(): void

Defined in: composite-animation.ts:1089

Returns ​

void

Implementation of ​

Animator.resetAnimationState


resume() ​

resume(): void

Defined in: composite-animation.ts:820

Returns ​

void

Implementation of ​

Animator.resume


setParent() ​

setParent(parent): void

Defined in: composite-animation.ts:1135

Parameters ​

parent ​

AnimatorContainer

Returns ​

void

Implementation of ​

Animator.setParent


setUp() ​

setUp(): void

Defined in: composite-animation.ts:1037

Returns ​

void

Implementation of ​

Animator.setUp


start() ​

start(): void

Defined in: composite-animation.ts:801

Returns ​

void

Implementation of ​

Animator.start


stop() ​

stop(): void

Defined in: composite-animation.ts:809

Returns ​

void

Implementation of ​

Animator.stop


tearDown() ​

tearDown(): void

Defined in: composite-animation.ts:1042

Returns ​

void

Implementation of ​

Animator.tearDown


toggleReverse() ​

toggleReverse(reverse): void

Defined in: composite-animation.ts:797

Parameters ​

reverse ​

boolean

Returns ​

void

Implementation of ​

Animator.toggleReverse


wrapUp() ​

wrapUp(): void

Defined in: composite-animation.ts:1096

Returns ​

void