"use client"; import { cn } from "@/lib/utils"; import React, { useEffect, useState } from "react"; export const InfiniteMovingCards = ({ items, direction = "left", speed = "fast", pauseOnHover = true, className, }: { items: { src: string; alt: string; }[]; direction?: "left" | "right"; speed?: "fast" | "normal" | "slow"; pauseOnHover?: boolean; className?: string; }) => { const containerRef = React.useRef(null); const scrollerRef = React.useRef(null); useEffect(() => { addAnimation(); }, []); const [start, setStart] = useState(false); function addAnimation() { if (containerRef.current && scrollerRef.current) { const scrollerContent = Array.from(scrollerRef.current.children); // Duplicate items for infinite scrolling effect scrollerContent.forEach((item) => { const duplicatedItem = item.cloneNode(true); if (scrollerRef.current) { scrollerRef.current.appendChild(duplicatedItem); } }); getDirection(); getSpeed(); setStart(true); } } const getDirection = () => { if (containerRef.current) { containerRef.current.style.setProperty( "--animation-direction", direction === "left" ? "forwards" : "reverse" ); } }; const getSpeed = () => { if (containerRef.current) { const durationMap: Record = { fast: "20s", normal: "40s", slow: "80s", }; containerRef.current.style.setProperty("--animation-duration", durationMap[speed]); } }; return (
    {items.map((item, idx) => (
  • {item.alt}
  • ))}
); };