Marquee
A row of cards that scrolls on its own, without end.
A row of cards that scrolls on its own, without end.
npx shadcn@latest add @magicui/marquee
First time with Magic UI? Set it up once.
/**
* Component from Magic UI, https://magicui.design
* MIT License, Copyright (c) Magic UI. Full text: https://github.com/magicuidesign/magicui/blob/main/LICENSE.md
*/
import { type ComponentPropsWithoutRef } from "react"
import { cn } from "@/lib/utils"
interface MarqueeProps extends ComponentPropsWithoutRef<"div"> {
/**
* Optional CSS class name to apply custom styles
*/
className?: string
/**
* Whether to reverse the animation direction
* @default false
*/
reverse?: boolean
/**
* Whether to pause the animation on hover
* @default false
*/
pauseOnHover?: boolean
/**
* Content to be displayed in the marquee
*/
children: React.ReactNode
/**
* Whether to animate vertically instead of horizontally
* @default false
*/
vertical?: boolean
/**
* Number of times to repeat the content
* @default 4
*/
repeat?: number
}
export function Marquee({
className,
reverse = false,
pauseOnHover = false,
children,
vertical = false,
repeat = 4,
...props
}: MarqueeProps) {
return (
<div
{...props}
className={cn(
"group flex gap-(--gap) overflow-hidden p-2 [--duration:40s] [--gap:1rem]",
{
"flex-row": !vertical,
"flex-col": vertical,
},
className
)}
>
{Array(repeat)
.fill(0)
.map((_, i) => (
<div
key={i}
className={cn("flex shrink-0 justify-around gap-(--gap)", {
"animate-marquee flex-row": !vertical,
"animate-marquee-vertical flex-col": vertical,
"group-hover:[animation-play-state:paused]": pauseOnHover,
"[animation-direction:reverse]": reverse,
})}
>
{children}
</div>
))}
</div>
)
}
/* Add to your global CSS (after @import "tailwindcss"). From Magic UI, MIT License. */
@theme inline {
--animate-marquee: marquee var(--duration) infinite linear;
--animate-marquee-vertical: marquee-vertical var(--duration) linear infinite;
@keyframes marquee {
from {
transform: translateX(0);
}
to {
transform: translateX(calc(-100% - var(--gap)));
}
}
@keyframes marquee-vertical {
from {
transform: translateY(0);
}
to {
transform: translateY(calc(-100% - var(--gap)));
}
}
}
/**
* Demo from Magic UI, https://magicui.design
* MIT License, Copyright (c) Magic UI. Full text: https://github.com/magicuidesign/magicui/blob/main/LICENSE.md
* Changed for Tastebud: coloured initials instead of avatar pictures.
*/
import { cn } from "@/lib/utils"
import { Marquee } from "@/components/ui/marquee"
const reviews = [
{
name: "Jack",
username: "@jack",
body: "I've never seen anything like this before. It's amazing. I love it.",
color: "#1ABCFE",
},
{
name: "Jill",
username: "@jill",
body: "I don't know what to say. I'm speechless. This is amazing.",
color: "#A259FF",
},
{
name: "John",
username: "@john",
body: "I'm at a loss for words. This is amazing. I love it.",
color: "#0ACF83",
},
{
name: "Jane",
username: "@jane",
body: "I'm at a loss for words. This is amazing. I love it.",
color: "#F24E1E",
},
{
name: "Jenny",
username: "@jenny",
body: "I'm at a loss for words. This is amazing. I love it.",
color: "#FFC700",
},
{
name: "James",
username: "@james",
body: "I'm at a loss for words. This is amazing. I love it.",
color: "#FF7262",
},
]
const firstRow = reviews.slice(0, reviews.length / 2)
const secondRow = reviews.slice(reviews.length / 2)
const ReviewCard = ({
color,
name,
username,
body,
}: {
color: string
name: string
username: string
body: string
}) => {
return (
<figure
className={cn(
"relative h-full w-64 cursor-pointer overflow-hidden rounded-xl border p-4",
// light styles
"border-gray-950/[.1] bg-gray-950/[.01] hover:bg-gray-950/[.05]",
// dark styles
"dark:border-gray-50/[.1] dark:bg-gray-50/[.10] dark:hover:bg-gray-50/[.15]"
)}
>
<div className="flex flex-row items-center gap-2">
<span
className="flex size-8 items-center justify-center rounded-full text-sm font-medium text-white"
style={{ backgroundColor: color }}
aria-hidden="true"
>
{name[0]}
</span>
<div className="flex flex-col">
<figcaption className="text-sm font-medium dark:text-white">
{name}
</figcaption>
<p className="text-xs font-medium dark:text-white/40">{username}</p>
</div>
</div>
<blockquote className="mt-2 text-sm">{body}</blockquote>
</figure>
)
}
export default function MarqueeDemo() {
return (
<div className="relative flex w-full flex-col items-center justify-center overflow-hidden">
<Marquee pauseOnHover className="[--duration:20s]">
{firstRow.map((review) => (
<ReviewCard key={review.username} {...review} />
))}
</Marquee>
<Marquee reverse pauseOnHover className="[--duration:20s]">
{secondRow.map((review) => (
<ReviewCard key={review.username} {...review} />
))}
</Marquee>
<div className="from-background pointer-events-none absolute inset-y-0 left-0 w-1/4 bg-gradient-to-r"></div>
<div className="from-background pointer-events-none absolute inset-y-0 right-0 w-1/4 bg-gradient-to-l"></div>
</div>
)
}
Changed for this site: Coloured initials instead of avatar pictures.