"use client"; import { cn } from "@/lib/utils"; import React, { useEffect, useRef, useState } from "react"; export const InfiniteMovingCards = ({ items, direction = "left", speed = "slow", pauseOnHover = true, className, }: { items: React.ReactNode[]; direction?: "left" | "right"; speed?: "fast" | "normal" | "slow"; pauseOnHover?: boolean; className?: string; }) => { const containerRef = useRef(null); const scrollerRef = useRef(null); const [isReady, setIsReady] = useState(false); useEffect(() => { if (!scrollerRef.current) return; const children = Array.from(scrollerRef.current.children); // duplicate each item ONCE children.forEach((item) => { const clone = item.cloneNode(true); scrollerRef.current!.appendChild(clone); }); // set speed variable const duration = speed === "fast" ? "20s" : speed === "normal" ? "40s" : "80s"; containerRef.current?.style.setProperty( "--animation-duration", duration ); // set direction variable containerRef.current?.style.setProperty( "--animation-direction", direction === "left" ? "forwards" : "reverse" ); setIsReady(true); }, [direction, speed]); return (
    {items.map((item, i) => (
  • {item}
  • ))}
); };