Skip to content

@ue-too/animate / index / Animation

類別: Animation<T>

定義於: composite-animation.ts:740

Keyframe-based animation for a single value.

備註

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

範例

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;
}

型別參數

T

T

The type of value being animated

實作

建構函式

建構函式

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

定義於: composite-animation.ts:766

參數

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

回傳

Animation<T>

存取器

delay

Getter 簽章

get delay(): number

定義於: composite-animation.ts:1102

回傳

number

Setter 簽章

set delay(delayTime): void

定義於: composite-animation.ts:1106

參數
delayTime

number

回傳

void

實作了

Animator.delay


drag

Getter 簽章

get drag(): number

定義於: composite-animation.ts:1113

回傳

number

Setter 簽章

set drag(dragTime): void

定義於: composite-animation.ts:1117

參數
dragTime

number

回傳

void

實作了

Animator.drag


duration

Getter 簽章

get duration(): number

定義於: composite-animation.ts:1054

回傳

number

Setter 簽章

set duration(duration): void

定義於: composite-animation.ts:1058

參數
duration

number

回傳

void

實作了

Animator.duration


easeFunction

Getter 簽章

get easeFunction(): (percentage) => number

定義於: composite-animation.ts:1156

回傳

(percentage): number

參數
percentage

number

回傳

number

Setter 簽章

set easeFunction(easeFn): void

定義於: composite-animation.ts:1160

參數
easeFn

(percentage) => number

回傳

void


keyFrames

Getter 簽章

get keyFrames(): Keyframe<T>[]

定義於: composite-animation.ts:1152

回傳

Keyframe<T>[]

Setter 簽章

set keyFrames(keyFrames): void

定義於: composite-animation.ts:1143

參數
keyFrames

Keyframe<T>[]

回傳

void


loops

Getter 簽章

get loops(): boolean

定義於: composite-animation.ts:1046

回傳

boolean

Setter 簽章

set loops(loop): void

定義於: composite-animation.ts:1050

參數
loop

boolean

回傳

void

實作了

Animator.loops


maxLoopCount

Getter 簽章

get maxLoopCount(): number | undefined

定義於: composite-animation.ts:1196

回傳

number | undefined

Setter 簽章

set maxLoopCount(maxLoopCount): void

定義於: composite-animation.ts:1200

參數
maxLoopCount

number | undefined

回傳

void

實作了

Animator.maxLoopCount


playing

Getter 簽章

get playing(): boolean

定義於: composite-animation.ts:824

回傳

boolean

實作了

Animator.playing


trueDuration

Getter 簽章

get trueDuration(): number

定義於: composite-animation.ts:1124

回傳

number

Setter 簽章

set trueDuration(duration): void

定義於: composite-animation.ts:1128

參數
duration

number

回傳

void

方法

animate()

animate(deltaTime): void

定義於: composite-animation.ts:828

參數

deltaTime

number

回傳

void

實作了

Animator.animate


clearOnEnd()

clearOnEnd(): void

定義於: composite-animation.ts:1188

回傳

void

實作了

Animator.clearOnEnd


clearOnStart()

clearOnStart(): void

定義於: composite-animation.ts:1192

回傳

void

實作了

Animator.clearOnStart


detachParent()

detachParent(): void

定義於: composite-animation.ts:1139

回傳

void

實作了

Animator.detachParent


findValue()

findValue(valuePercentage, keyframes, animatableAttributeHelper): T

定義於: composite-animation.ts:957

參數

valuePercentage

number

keyframes

Keyframe<T>[]

animatableAttributeHelper

AnimatableAttributeHelper<T>

回傳

T


nonCascadingDuration()

nonCascadingDuration(newDuration): void

定義於: composite-animation.ts:1075

參數

newDuration

number

回傳

void

實作了

Animator.nonCascadingDuration


onEnd()

onEnd(callback): UnSubscribe

定義於: composite-animation.ts:1164

參數

callback

Function

回傳

UnSubscribe

實作了

Animator.onEnd


onStart()

onStart(callback): UnSubscribe

定義於: composite-animation.ts:1171

參數

callback

Function

回傳

UnSubscribe

實作了

Animator.onStart


onStartAfterDelay()

onStartAfterDelay(callback): UnSubscribe

定義於: composite-animation.ts:1180

參數

callback

Function

回傳

UnSubscribe


pause()

pause(): void

定義於: composite-animation.ts:816

回傳

void

實作了

Animator.pause


resetAnimationState()

resetAnimationState(): void

定義於: composite-animation.ts:1089

回傳

void

實作了

Animator.resetAnimationState


resume()

resume(): void

定義於: composite-animation.ts:820

回傳

void

實作了

Animator.resume


setParent()

setParent(parent): void

定義於: composite-animation.ts:1135

參數

parent

AnimatorContainer

回傳

void

實作了

Animator.setParent


setUp()

setUp(): void

定義於: composite-animation.ts:1037

回傳

void

實作了

Animator.setUp


start()

start(): void

定義於: composite-animation.ts:801

回傳

void

實作了

Animator.start


stop()

stop(): void

定義於: composite-animation.ts:809

回傳

void

實作了

Animator.stop


tearDown()

tearDown(): void

定義於: composite-animation.ts:1042

回傳

void

實作了

Animator.tearDown


toggleReverse()

toggleReverse(reverse): void

定義於: composite-animation.ts:797

參數

reverse

boolean

回傳

void

實作了

Animator.toggleReverse


wrapUp()

wrapUp(): void

定義於: composite-animation.ts:1096

回傳

void