Getting Started
Blocks
Components
Device Mocks
Special Effects
Animations
Text Animations
Buttons
Velocity Scroll
Velocity Scroll
import {
ScrollVelocityContainer,
ScrollVelocityRow,
} from "@/registry/magicui/scroll-based-velocity";
export function ScrollBasedVelocityDemo() {
return (
<div className="relative flex w-full flex-col items-center justify-center overflow-hidden">
<ScrollVelocityContainer className="text-4xl md:text-7xl md:leading-[5rem] font-bold tracking-[-0.02em]">
<ScrollVelocityRow baseVelocity={20} direction={1}>
Velocity Scroll
</ScrollVelocityRow>
<ScrollVelocityRow baseVelocity={20} direction={-1}>
Velocity Scroll
</ScrollVelocityRow>
</ScrollVelocityContainer>
<div className="pointer-events-none absolute inset-y-0 left-0 w-1/4 bg-gradient-to-r from-background"></div>
<div className="pointer-events-none absolute inset-y-0 right-0 w-1/4 bg-gradient-to-l from-background"></div>
</div>
);
}
import {
ScrollVelocityContainer,
ScrollVelocityRow,
} from "@/registry/magicui/scroll-based-velocity";
const IMAGES_ROW_A = [
"https://images.unsplash.com/photo-1749738456487-2af715ab65ea?q=80&w=2340&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
"https://plus.unsplash.com/premium_photo-1720139288219-e20aa9c8895b?q=80&w=1810&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
];
const IMAGES_ROW_B = [
"https://images.unsplash.com/photo-1749738456487-2af715ab65ea?q=80&w=2340&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
"https://plus.unsplash.com/premium_photo-1720139288219-e20aa9c8895b?q=80&w=1810&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
];
export function ScrollBasedVelocityImagesDemo() {
return (
<div className="relative flex w-full flex-col items-center justify-center overflow-hidden py-8">
<ScrollVelocityContainer className="w-full">
<ScrollVelocityRow baseVelocity={6} direction={1} className="py-4">
{IMAGES_ROW_A.map((src, idx) => (
<img
key={idx}
src={`${src}&ixlib=rb-4.0.3`}
alt="Unsplash sample"
width={240}
height={160}
loading="lazy"
decoding="async"
className="mx-4 inline-block h-40 w-60 rounded-lg object-cover shadow-sm"
/>
))}
</ScrollVelocityRow>
<ScrollVelocityRow baseVelocity={6} direction={-1} className="py-4">
{IMAGES_ROW_B.map((src, idx) => (
<img
key={idx}
src={`${src}&ixlib=rb-4.0.3`}
alt="Unsplash sample"
width={240}
height={160}
loading="lazy"
decoding="async"
className="mx-4 inline-block h-40 w-60 rounded-lg object-cover shadow-sm"
/>
))}
</ScrollVelocityRow>
</ScrollVelocityContainer>
<div className="pointer-events-none absolute inset-y-0 left-0 w-1/4 bg-gradient-to-r from-background"></div>
<div className="pointer-events-none absolute inset-y-0 right-0 w-1/4 bg-gradient-to-l from-background"></div>
</div>
);
}
Installation
pnpm dlx shadcn@latest add @magicui/scroll-based-velocity
Usage
import {
ScrollVelocityContainer,
ScrollVelocityRow,
} from "@/components/magicui/scroll-based-velocity";
<ScrollVelocityContainer className="text-4xl md:text-7xl font-bold">
<ScrollVelocityRow baseVelocity={20} direction={1}>
Velocity Scroll
</ScrollVelocityRow>
<ScrollVelocityRow baseVelocity={20} direction={-1}>
Velocity Scroll
</ScrollVelocityRow>
</ScrollVelocityContainer>
Props
ScrollVelocityContainer
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | The class name to be applied to the component |
children | ReactNode | - | Content to be animated |
ScrollVelocityRow
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | The class name to be applied to the row container |
children | ReactNode | - | Content to be duplicated and scrolled |
baseVelocity | number | 5 | Base scroll velocity percentage of content width |
direction | 1 | -1 | 1 | Scroll direction (1 = left-to-right, -1 = reverse) |
Performance
- Pauses updates when offscreen and when the tab is hidden.
- Respects user preference for reduced motion.
Limited Time Offer
Ship Faster with Magic UI ProMagic UI Pro
Stop building from scratch.
Get 8 production-ready templates and 50+ premium components that your users will love.
✓
Next.js 15 + TypeScript ready✓
Copy, paste, customize in minutes✓
Save 100+ hours of development