Build FasterShip BetterNever Settle
Build FasterShip BetterNever Settle
Build FasterShip BetterNever Settle
Build FasterShip BetterNever Settle
Framer Motion
Tailwind CSS
React Server Components
Responsive
Type Safe
Framer Motion
Tailwind CSS
React Server Components
Responsive
Type Safe
Framer Motion
Tailwind CSS
React Server Components
Responsive
Type Safe
Framer Motion
Tailwind CSS
React Server Components
Responsive
Type Safe
Scroll up and down quickly to see the marquee accelerate.
Installation
npx kinetic-ui-cli@latest add velocity-marqueeUsage
import { VelocityMarquee } from "@/components/creative/velocity-marquee";
export default function Page() {
return (
<VelocityMarquee baseVelocity={5}>
<span className="text-4xl font-bold px-4">
Scroll fast to see me accelerate!
</span>
</VelocityMarquee>
);
}
How it works
This component leverages Framer Motion's useScroll and useVelocity hooks to calculate how fast the user is scrolling the page.
- Velocity Tracking: As you scroll,
useVelocityoutputs the scroll speed in pixels per second. - Spring Dampening: We pass the raw velocity into a
useSpringto smooth out sudden stops (so the marquee doesn't jerk violently when you stop scrolling). - Animation Loop: A
useAnimationFrameloop continuously updates thexposition of the items. It calculates the offset by combining thebaseVelocitywith the dampened scroll velocity factor. - Wrapping: Finally,
wrap()ensures that when the items scroll out of view on one side, they seamlessly snap back to the other side to create the infinite illusion.
Usage Guide
1. Import the Component
Import the component into your React or Next.js page:
import { VelocityMarquee } from "@/components/creative/velocity-marquee";
2. Implementation Example
Render the component and customize its behavior by passing props:
import { VelocityMarquee } from "@/components/creative/velocity-marquee";
export default function Example() {
return (
<div className="w-full flex items-center justify-center p-8">
<VelocityMarquee
baseVelocity{10}
itemClassName="example"
repeatCount{10}
>
<div>Content goes here</div>
</VelocityMarquee>
</div>
);
}