Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/marquee.jsonFirst component? Set up your project first
Frameworks
The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.
"use client";
import * as React from "react";
import { motion, useAnimationFrame, useMotionValue } from "motion/react";
import { cn } from "@/lib/utils";
import { useReduceMotion } from "./motion";
export type MarqueeProps = React.ComponentProps<"div"> & {
speed?: number;
reverse?: boolean;
pauseOnHover?: boolean;
fade?: boolean;
gap?: number;
repeat?: number;
itemClassName?: string;
};
export function Marquee({
speed = 42,
reverse = false,
pauseOnHover = true,
fade = true,
gap = 32,
repeat = 2,
itemClassName,
className,
children,
style,
onPointerEnter,
onPointerLeave,
...props
}: MarqueeProps) {
const reduce = useReduceMotion();
const [paused, setPaused] = React.useState(false);
const [ready, setReady] = React.useState(false);
const trackRef = React.useRef<HTMLDivElement>(null);
const firstRef = React.useRef<HTMLDivElement>(null);
const spanRef = React.useRef(0);
const x = useMotionValue(0);
const direction = reverse ? 1 : -1;
React.useLayoutEffect(() => {
const node = firstRef.current;
if (!node) return;
const measure = () => {
const width = node.scrollWidth + gap;
spanRef.current = width;
if (reverse) x.set(-width);
setReady(width > 0);
};
measure();
const observer = new ResizeObserver(measure);
observer.observe(node);
return () => observer.disconnect();
}, [gap, reverse, x, children]);
useAnimationFrame((_, delta) => {
if (reduce || paused || !ready || speed <= 0) return;
const step = (speed * Math.min(delta, 64)) / 1000;
let next = x.get() + direction * step;
const span = spanRef.current;
if (span <= 0) return;
if (!reverse && next <= -span) next += span;
if (reverse && next >= 0) next -= span;
x.set(next);
});
const copies = Math.max(2, Math.round(repeat));
const items = Array.from({ length: copies }, (_, copy) => (
<div
key={copy}
ref={copy === 0 ? firstRef : undefined}
aria-hidden={copy > 0 ? "true" : undefined}
className={cn("flex shrink-0 items-center", itemClassName)}
style={{ gap }}
>
{children}
</div>
));
return (
<div
data-slot="marquee"
className={cn("relative overflow-hidden", className)}
style={{
...style,
maskImage: fade
? "linear-gradient(to right, transparent, black 10%, black 90%, transparent)"
: undefined,
WebkitMaskImage: fade
? "linear-gradient(to right, transparent, black 10%, black 90%, transparent)"
: undefined,
}}
onPointerEnter={(event) => {
onPointerEnter?.(event);
if (pauseOnHover) setPaused(true);
}}
onPointerLeave={(event) => {
onPointerLeave?.(event);
if (pauseOnHover) setPaused(false);
}}
{...props}
>
<motion.div
ref={trackRef}
className="flex w-max items-center will-change-transform"
style={{ x, gap }}
data-paused={paused ? "true" : undefined}
>
{items}
</motion.div>
</div>
);
}Install
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/marquee.jsonDependencies
motion lucide-reactThe registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.
Usage
Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.
import { Marquee } from "@/components/prequelui/marquee";
export default function Demo() {
return (
<Marquee speed={34} gap={10} pauseOnHover>
{["Design", "Docs", "Checkout", "Analytics"].map((item) => (
<span key={item}>{item}</span>
))}
</Marquee>
);
}import { Marquee } from "@/components/prequelui/marquee";
export function Variant() {
return (
<Marquee tempo={1.2}>
…
</Marquee>
);
}Animation
The row is duplicated and translated in a single motion value. When the first copy has travelled exactly its own width, the offset wraps by that width, so there is no seam and no re-render per frame.
- Speed is expressed in pixels per second, independent of the content width.
- The wrap happens one frame before the seam becomes visible.
- Pausing freezes the current offset; it never snaps back to zero.
- The fade mask is 10% on each edge and can be turned off.
- Reduced motion holds the first copy still.
API Reference
Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.
Marquee
| Prop | Type | Default |
|---|---|---|
| speed | number | 42 |
| reverse | boolean | false |
| pauseOnHover | boolean | true |
| fade | boolean | true |
| gap | number | 32 |
| repeat | number | 2 |
| itemClassName | string | — |
| className | string | — |