@huth/animate
v3.0.0
Published
A simple, bare bones animation utility for time-based animations of numbers and hex color values.
Downloads
15
Readme
animate
A simple, bare bones animation utility for time-based animations of numbers and hex color values.
npm install @huth/animate
- Animate!
import animate from "@huth/animate"
let stop = animate({
from: 0,
to: 100,
duration: 750,
delay: 200,
easing: (t) => t ** 3,
render: (value) => console.log(value),
start: () => console.log("animation started"),
end: () => console.log("animation complete"),
cancel: () => console.log("animation stopped"),
})
// stop() call me to stop animation
from
andto
can be either a number or a full CSS string hex color value (#FF0000
), or an object with those values.duration
timing in milliseconds.delay
time before animation starts, in milliseconds.easing
easing function that returns a value between0
and1
.render
callback called with the interpolated value for every animation stepstart
callback called when the animation starts (after delay)end
callback called when the animation has finishedcancel
callback called if the animation was stopped before it had a chance to finish
In addition, the animate
method returns a function that when called will kill the animation (and trigger any cancel
callback).