A infinite-moving-cards component from Aceternity UI.
From Aceternity UI
1"use client";
2
3import { cn } from "@/lib/utils";
4import React, { useEffect, useState } from "react";
5
6export const InfiniteMovingCards = ({
7 items,
8 direction = "left",
9 speed = "fast",
10 pauseOnHover = true,
11 className,
12}: {
13 items: {
14 quote: string;
15 name: string;
16 title: string;
17 }[];
18 direction?: "left" | "right";
19 speed?: "fast" | "normal" | "slow";
20 pauseOnHover?: boolean;
21 className?: string;
22}) => {
23 const containerRef = React.useRef<HTMLDivElement>(null);
24 const scrollerRef = React.useRef<HTMLUListElement>(null);
25
26 useEffect(() => {
27 addAnimation();
28 }, []);
29 const [start, setStart] = useState(false);
30 function addAnimation() {
31 if (containerRef.current && scrollerRef.current) {
32 const scrollerContent = Array.from(scrollerRef.current.children);
33
34 scrollerContent.forEach((item) => {
35 const duplicatedItem = item.cloneNode(true);
36 if (scrollerRef.current) {
37 scrollerRef.current.appendChild(duplicatedItem);
38 }
39 });
40
41 getDirection();
42 getSpeed();
43 setStart(true);
44 }
45 }
46 const getDirection = () => {
47 if (containerRef.current) {
48 if (direction === "left") {
49 containerRef.current.style.setProperty(
50 "--animation-direction",
51 "forwards",
52 );
53 } else {
54 containerRef.current.style.setProperty(
55 "--animation-direction",
56 "reverse",
57 );
58 }
59 }
60 };
61 const getSpeed = () => {
62 if (containerRef.current) {
63 if (speed === "fast") {
64 containerRef.current.style.setProperty("--animation-duration", "20s");
65 } else if (speed === "normal") {
66 containerRef.current.style.setProperty("--animation-duration", "40s");
67 } else {
68 containerRef.current.style.setProperty("--animation-duration", "80s");
69 }
70 }
71 };
72 return (
73 <div
74 ref={containerRef}
75 className={cn(
76 "scroller relative z-20 max-w-7xl overflow-hidden [mask-image:linear-gradient(to_right,transparent,white_20%,white_80%,transparent)]",
77 className,
78 )}
79 >
80 <ul
81 ref={scrollerRef}
82 className={cn(
83 "flex w-max min-w-full shrink-0 flex-nowrap gap-4 py-4",
84 start && "animate-scroll",
85 pauseOnHover && "hover:[animation-play-state:paused]",
86 )}
87 >
88 {items.map((item, idx) => (
89 <li
90 className="relative w-[350px] max-w-full shrink-0 rounded-2xl border border-b-0 border-zinc-200 bg-[linear-gradient(180deg,#fafafa,#f5f5f5)] px-8 py-6 md:w-[450px] dark:border-zinc-700 dark:bg-[linear-gradient(180deg,#27272a,#18181b)]"
91 key={item.name}
92 >
93 <blockquote>
94 <div
95 aria-hidden="true"
96 className="user-select-none pointer-events-none absolute -top-0.5 -left-0.5 -z-1 h-[calc(100%_+_4px)] w-[calc(100%_+_4px)]"
97 ></div>
98 <span className="relative z-20 text-sm leading-[1.6] font-normal text-neutral-800 dark:text-gray-100">
99 {item.quote}
100 </span>
101 <div className="relative z-20 mt-6 flex flex-row items-center">
102 <span className="flex flex-col gap-1">
103 <span className="text-sm leading-[1.6] font-normal text-neutral-500 dark:text-gray-400">
104 {item.name}
105 </span>
106 <span className="text-sm leading-[1.6] font-normal text-neutral-500 dark:text-gray-400">
107 {item.title}
108 </span>
109 </span>
110 </div>
111 </blockquote>
112 </li>
113 ))}
114 </ul>
115 </div>
116 );
117};
118