@ue-too/animate / 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
- Define keyframes at percentages (0.0 to 1.0) along the timeline
- Provide a callback to apply the animated value
- Provide an interpolation helper for the value type
- Call
animate(deltaTime)each frame to progress the animation
Example
Animating a number with easing
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
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
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
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
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
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
playing
Get Signature
get playing():
boolean
Defined in: composite-animation.ts:824
Returns
boolean
Implementation of
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
clearOnEnd()
clearOnEnd():
void
Defined in: composite-animation.ts:1188
Returns
void
Implementation of
clearOnStart()
clearOnStart():
void
Defined in: composite-animation.ts:1192
Returns
void
Implementation of
detachParent()
detachParent():
void
Defined in: composite-animation.ts:1139
Returns
void
Implementation of
findValue()
findValue(
valuePercentage,keyframes,animatableAttributeHelper):T
Defined in: composite-animation.ts:957
Parameters
valuePercentage
number
keyframes
Keyframe<T>[]
animatableAttributeHelper
Returns
T
nonCascadingDuration()
nonCascadingDuration(
newDuration):void
Defined in: composite-animation.ts:1075
Parameters
newDuration
number
Returns
void
Implementation of
onEnd()
onEnd(
callback):UnSubscribe
Defined in: composite-animation.ts:1164
Parameters
callback
Function
Returns
Implementation of
onStart()
onStart(
callback):UnSubscribe
Defined in: composite-animation.ts:1171
Parameters
callback
Function
Returns
Implementation of
onStartAfterDelay()
onStartAfterDelay(
callback):UnSubscribe
Defined in: composite-animation.ts:1180
Parameters
callback
Function
Returns
pause()
pause():
void
Defined in: composite-animation.ts:816
Returns
void
Implementation of
resetAnimationState()
resetAnimationState():
void
Defined in: composite-animation.ts:1089
Returns
void
Implementation of
resume()
resume():
void
Defined in: composite-animation.ts:820
Returns
void
Implementation of
setParent()
setParent(
parent):void
Defined in: composite-animation.ts:1135
Parameters
parent
Returns
void
Implementation of
setUp()
setUp():
void
Defined in: composite-animation.ts:1037
Returns
void
Implementation of
start()
start():
void
Defined in: composite-animation.ts:801
Returns
void
Implementation of
stop()
stop():
void
Defined in: composite-animation.ts:809
Returns
void
Implementation of
tearDown()
tearDown():
void
Defined in: composite-animation.ts:1042
Returns
void
Implementation of
toggleReverse()
toggleReverse(
reverse):void
Defined in: composite-animation.ts:797
Parameters
reverse
boolean
Returns
void
Implementation of
wrapUp()
wrapUp():
void
Defined in: composite-animation.ts:1096
Returns
void