@samuelpetersson/animate v0.7.0
Animate
Animate async functions in controllable scopes.
Install
npm install @samuelpetersson/animate
Usage
import animate, {curve, blend} from '@samuelpetersson/animate'
//Tween background color
await animate.tween({duration: 2}, blend.style(document.body, {backgroundColor:'#FF0099'}))
//Wait 1 second...
await animate.delay(1)
//Bullet time!
animate.scale = 0.1
//Tween myElement width and height
await animate.tween({duration: 2, curve: curve.smoothstep}, blend.style(myElement, {width:'100%', height:'400px'}))
//Stop all animations created in the animate scope
animate.clear()
//Create a new scope
var {tween} = animate.scope()
//Tween custom value
await tween({duration:4}, (f) => console.log('Current tween value:', f))Reference
scope (animate)
pause:booleanIndicates whether the scope is paused or not.scale:numberDelta time multiplier. (use this to speed up or slow down an entire scope)scope(scale:number = 1):ScopeReturns a new scope.clear()Clear all animations in current scope.until(solve:(deltaTime:number) => boolean):PromiseResolves when the solve function returns true.every(items:Promise[]):PromiseResolves when all promises in the items array has resolved.delay(duration:number):PromiseResolves when the accumulated time has reachedduration.tween({duration:number, curve:(t:number) => number}, mixer:(f:number) => void):PromiseRunsmixerwith the accumulated time normalized (0 to 1).durationspecifies duration in seconds.curvespecifies a function to ease the normalized value.fixed({fps:number, max:number}, update:(fixedDeltaTime:number) => boolean, render:(progress:number) => void)Runsupdatewith a fixed delta time andrenderwith the progress in the last time step.fpsspecifies update frames per seconds.maxspecifies an update limit.
curve
smoothstep(t:number) => numbersmootherstep(t:number) => numberpowerIn(exp):(t:number) => numberpowerOut(exp):(t:number) => numberpowerInOut(exp):(t:number) => number
blend
float(a:number, b:number, t:number):numberReturns float between a and b.color(a:number, b:number, t:number):numberReturns color between a and b.angle(a:number, b:number, t:number):numberReturns angle between a and b.mixer(target:Object, values:Object, create:(property) => (t:number) => void)Returns a new mixer function.style(target:Element, values:Object)Returns a new mixer function .