1.0.0 • Published 2 years ago
rotulus v1.0.0
📜 Rotulus
Minimal wheel/scroll based animator for React
Installation
npm install rotulusUsage
function SimpleAnimation() {
return (
<WheelAnimationProvider max={1000}>
<MovingText />
</WheelAnimationProvider>
)
}
function MovingText() {
const moveAnimation = [
{
start: 0, // start value
end: 500, // end value
startFrame: 0, // start frame
endFrame: 1000, // end frame
type: 'translateY', // property to animate
unit: 'px', // unit for property
},
]
return (
<WheelAnimationComponent animations={moveAnimation}>
Scroll to see this text move!
</WheelAnimationComponent>
)
}How it works
Rotulus uses React's Context API internally.
WheelAnimationProvidertracks the wheel progress by listening to browser's wheel eventWheelAnimationComponentregisters a callback to the provider's context on mount (The callback contains the logic to update property on each frame)WheelAnimationProviderruns the callback on each frame (by using requestAnimationFrame) thus synchronizing everyWheelAnimationComponentto wheel progress that is in the Provider
It's as simple as that!
Contribute
Any kind of feedback is welcome!
1.0.0
2 years ago