diff --git a/components/ui/infinite-moving-cards.tsx b/components/ui/infinite-moving-cards.tsx new file mode 100644 index 0000000..90c3a45 --- /dev/null +++ b/components/ui/infinite-moving-cards.tsx @@ -0,0 +1,85 @@ +"use client"; + +import { cn } from "@/lib/utils"; +import React, { useEffect, useState } from "react"; + +export const InfiniteMovingCards = ({ + direction = "left", + speed = "fast", + pauseOnHover = true, + children, +}: { + direction?: "left" | "right"; + speed?: "fast" | "normal" | "slow"; + pauseOnHover?: boolean; + children: React.ReactNode; +}) => { + 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); + + scrollerContent.forEach((item) => { + const duplicatedItem = item.cloneNode(true); + if (scrollerRef.current) { + scrollerRef.current.appendChild(duplicatedItem); + } + }); + + getDirection(); + getSpeed(); + setStart(true); + } + } + const getDirection = () => { + if (containerRef.current) { + if (direction === "left") { + containerRef.current.style.setProperty( + "--animation-direction", + "forwards", + ); + } else { + containerRef.current.style.setProperty( + "--animation-direction", + "reverse", + ); + } + } + }; + const getSpeed = () => { + if (containerRef.current) { + if (speed === "fast") { + containerRef.current.style.setProperty("--animation-duration", "20s"); + } else if (speed === "normal") { + containerRef.current.style.setProperty("--animation-duration", "40s"); + } else { + containerRef.current.style.setProperty("--animation-duration", "80s"); + } + } + }; + return ( +
+
+ {children} +
+
+ ); +};