|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { motion } from "motion/react"; |
| 4 | +import { cn } from "~/lib/utils"; |
| 5 | +export const ThreeDMarquee = ({ |
| 6 | + images, |
| 7 | + className, |
| 8 | +}: { |
| 9 | + images: string[]; |
| 10 | + className?: string; |
| 11 | +}) => { |
| 12 | + // Split the images array into 4 equal parts |
| 13 | + const chunkSize = Math.ceil(images.length / 4); |
| 14 | + const chunks = Array.from({ length: 4 }, (_, colIndex) => { |
| 15 | + const start = colIndex * chunkSize; |
| 16 | + return images.slice(start, start + chunkSize); |
| 17 | + }); |
| 18 | + return ( |
| 19 | + <div |
| 20 | + className={cn( |
| 21 | + "mx-auto block h-[600px] overflow-hidden rounded-2xl max-sm:h-100", |
| 22 | + className, |
| 23 | + )} |
| 24 | + > |
| 25 | + <div className="flex size-full items-center justify-center"> |
| 26 | + <div className="size-[1720px] shrink-0 scale-50 sm:scale-75 lg:scale-100"> |
| 27 | + <div |
| 28 | + style={{ |
| 29 | + transform: "rotateX(55deg) rotateY(0deg) rotateZ(-45deg)", |
| 30 | + }} |
| 31 | + className="relative top-96 right-[50%] grid size-full origin-top-left grid-cols-4 gap-8 transform-3d" |
| 32 | + > |
| 33 | + {chunks.map((subarray, colIndex) => ( |
| 34 | + <motion.div |
| 35 | + animate={{ y: colIndex % 2 === 0 ? 100 : -100 }} |
| 36 | + transition={{ |
| 37 | + duration: colIndex % 2 === 0 ? 10 : 15, |
| 38 | + repeat: Infinity, |
| 39 | + repeatType: "reverse", |
| 40 | + }} |
| 41 | + key={colIndex + "marquee"} |
| 42 | + className="flex flex-col items-start gap-8" |
| 43 | + > |
| 44 | + <GridLineVertical className="-left-4" offset="80px" /> |
| 45 | + {subarray.map((image, imageIndex) => ( |
| 46 | + <div className="relative" key={imageIndex + image}> |
| 47 | + <GridLineHorizontal className="-top-4" offset="20px" /> |
| 48 | + <motion.img |
| 49 | + whileHover={{ |
| 50 | + y: -10, |
| 51 | + }} |
| 52 | + transition={{ |
| 53 | + duration: 0.3, |
| 54 | + ease: "easeInOut", |
| 55 | + }} |
| 56 | + key={imageIndex + image} |
| 57 | + src={image} |
| 58 | + alt={`Image ${imageIndex + 1}`} |
| 59 | + className="aspect-[970/700] rounded-lg object-cover ring ring-gray-950/5 hover:shadow-2xl" |
| 60 | + width={970} |
| 61 | + height={700} |
| 62 | + /> |
| 63 | + </div> |
| 64 | + ))} |
| 65 | + </motion.div> |
| 66 | + ))} |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + ); |
| 72 | +}; |
| 73 | + |
| 74 | +const GridLineHorizontal = ({ |
| 75 | + className, |
| 76 | + offset, |
| 77 | +}: { |
| 78 | + className?: string; |
| 79 | + offset?: string; |
| 80 | +}) => { |
| 81 | + return ( |
| 82 | + <div |
| 83 | + style={ |
| 84 | + { |
| 85 | + "--background": "#ffffff", |
| 86 | + "--color": "rgba(0, 0, 0, 0.2)", |
| 87 | + "--height": "1px", |
| 88 | + "--width": "5px", |
| 89 | + "--fade-stop": "90%", |
| 90 | + "--offset": offset || "200px", //-100px if you want to keep the line inside |
| 91 | + "--color-dark": "rgba(255, 255, 255, 0.2)", |
| 92 | + maskComposite: "exclude", |
| 93 | + } as React.CSSProperties |
| 94 | + } |
| 95 | + className={cn( |
| 96 | + "absolute left-[calc(var(--offset)/2*-1)] h-[var(--height)] w-[calc(100%+var(--offset))]", |
| 97 | + "bg-[linear-gradient(to_right,var(--color),var(--color)_50%,transparent_0,transparent)]", |
| 98 | + "[background-size:var(--width)_var(--height)]", |
| 99 | + "[mask:linear-gradient(to_left,var(--background)_var(--fade-stop),transparent),_linear-gradient(to_right,var(--background)_var(--fade-stop),transparent),_linear-gradient(black,black)]", |
| 100 | + "[mask-composite:exclude]", |
| 101 | + "z-30", |
| 102 | + "dark:bg-[linear-gradient(to_right,var(--color-dark),var(--color-dark)_50%,transparent_0,transparent)]", |
| 103 | + className, |
| 104 | + )} |
| 105 | + ></div> |
| 106 | + ); |
| 107 | +}; |
| 108 | + |
| 109 | +const GridLineVertical = ({ |
| 110 | + className, |
| 111 | + offset, |
| 112 | +}: { |
| 113 | + className?: string; |
| 114 | + offset?: string; |
| 115 | +}) => { |
| 116 | + return ( |
| 117 | + <div |
| 118 | + style={ |
| 119 | + { |
| 120 | + "--background": "#ffffff", |
| 121 | + "--color": "rgba(0, 0, 0, 0.2)", |
| 122 | + "--height": "5px", |
| 123 | + "--width": "1px", |
| 124 | + "--fade-stop": "90%", |
| 125 | + "--offset": offset || "150px", //-100px if you want to keep the line inside |
| 126 | + "--color-dark": "rgba(255, 255, 255, 0.2)", |
| 127 | + maskComposite: "exclude", |
| 128 | + } as React.CSSProperties |
| 129 | + } |
| 130 | + className={cn( |
| 131 | + "absolute top-[calc(var(--offset)/2*-1)] h-[calc(100%+var(--offset))] w-[var(--width)]", |
| 132 | + "bg-[linear-gradient(to_bottom,var(--color),var(--color)_50%,transparent_0,transparent)]", |
| 133 | + "[background-size:var(--width)_var(--height)]", |
| 134 | + "[mask:linear-gradient(to_top,var(--background)_var(--fade-stop),transparent),_linear-gradient(to_bottom,var(--background)_var(--fade-stop),transparent),_linear-gradient(black,black)]", |
| 135 | + "[mask-composite:exclude]", |
| 136 | + "z-30", |
| 137 | + "dark:bg-[linear-gradient(to_bottom,var(--color-dark),var(--color-dark)_50%,transparent_0,transparent)]", |
| 138 | + className, |
| 139 | + )} |
| 140 | + ></div> |
| 141 | + ); |
| 142 | +}; |
0 commit comments