Demo
https://animini.vercel.app/
Installation
For the React DOM
yarn add @animini/react-dom
For React Three Fiber
yarn add @animini/react-three
Instructions
import { useDrag } from '@use-gesture/react'
import { useAnimate, spring } from '@animini/react-dom'
const easing = spring()
export default function App() {
const [ref, api] = useAnimate()
useDrag(
({ active, movement: [x, y] }) => {
api.start({ scale: active ? 1.2 : 1, x: active ? x : 0, y: active ? y : 0 }, (k) => ({
immediate: k !== 'scale' && active,
easing
}))
},
{ target: ref }
)
return <div ref={ref} />
}
Easings
Lerp
Lerp is the lightest, fastest and default easing algorithm for Animini. It supports a factor
attribute that will change the momentum of the lerp.
import { useAnimate, lerp } from '@animini/react-dom'
const easing = lerp({ factor: 0.05 })
api.start({ x: 100 }, { easing })
Spring
import { useAnimate, spring } from '@animini/react-dom'
const easing = spring({
tension: 170,
friction: 26,
mass: 1,
velocity
})
api.start({ x: 100 }, { easing })
Ease (Bezier)
import { useAnimate, ease } from '@animini/react-dom'
const easing = ease(
300,
[0.25, 0.1, 0.25, 1]
)
api.start({ x: 100 }, { easing })
Inertia
Inertia aims at emulating a thrown object. Inertia will not reach its destination and only works if the value is already moving or if the easing is given an initial velocity.
Inertia supports min
and max
bounds which the element will bounce against as a rubberband bouncing on a wall.
import { useAnimate, inertia } from '@animini/react-dom'
const easing = inertia({
momentum: 0.998,
velocity: undefined,
min: -100,
max: 100,
rubberband = 0.15
})
api.start({ x: 100 }, { easing })