A hero-parallax component from Aceternity UI.
From Aceternity UI
1"use client";
2import React from "react";
3import {
4 motion,
5 useScroll,
6 useTransform,
7 useSpring,
8 MotionValue,
9} from "motion/react";
10
11
12
13export const HeroParallax = ({
14 products,
15}: {
16 products: {
17 title: string;
18 link: string;
19 thumbnail: string;
20 }[];
21}) => {
22 const firstRow = products.slice(0, 5);
23 const secondRow = products.slice(5, 10);
24 const thirdRow = products.slice(10, 15);
25 const ref = React.useRef(null);
26 const { scrollYProgress } = useScroll({
27 target: ref,
28 offset: ["start start", "end start"],
29 });
30
31 const springConfig = { stiffness: 300, damping: 30, bounce: 100 };
32
33 const translateX = useSpring(
34 useTransform(scrollYProgress, [0, 1], [0, 1000]),
35 springConfig
36 );
37 const translateXReverse = useSpring(
38 useTransform(scrollYProgress, [0, 1], [0, -1000]),
39 springConfig
40 );
41 const rotateX = useSpring(
42 useTransform(scrollYProgress, [0, 0.2], [15, 0]),
43 springConfig
44 );
45 const opacity = useSpring(
46 useTransform(scrollYProgress, [0, 0.2], [0.2, 1]),
47 springConfig
48 );
49 const rotateZ = useSpring(
50 useTransform(scrollYProgress, [0, 0.2], [20, 0]),
51 springConfig
52 );
53 const translateY = useSpring(
54 useTransform(scrollYProgress, [0, 0.2], [-700, 500]),
55 springConfig
56 );
57 return (
58 <div
59 ref={ref}
60 className="h-[300vh] py-40 overflow-hidden antialiased relative flex flex-col self-auto [perspective:1000px] [transform-style:preserve-3d]"
61 >
62 <Header />
63 <motion.div
64 style={{
65 rotateX,
66 rotateZ,
67 translateY,
68 opacity,
69 }}
70 className=""
71 >
72 <motion.div className="flex flex-row-reverse space-x-reverse space-x-20 mb-20">
73 {firstRow.map((product) => (
74 <ProductCard
75 product={product}
76 translate={translateX}
77 key={product.title}
78 />
79 ))}
80 </motion.div>
81 <motion.div className="flex flex-row mb-20 space-x-20 ">
82 {secondRow.map((product) => (
83 <ProductCard
84 product={product}
85 translate={translateXReverse}
86 key={product.title}
87 />
88 ))}
89 </motion.div>
90 <motion.div className="flex flex-row-reverse space-x-reverse space-x-20">
91 {thirdRow.map((product) => (
92 <ProductCard
93 product={product}
94 translate={translateX}
95 key={product.title}
96 />
97 ))}
98 </motion.div>
99 </motion.div>
100 </div>
101 );
102};
103
104export const Header = () => {
105 return (
106 <div className="max-w-7xl relative mx-auto py-20 md:py-40 px-4 w-full left-0 top-0">
107 <h1 className="text-2xl md:text-7xl font-bold dark:text-white">
108 The Ultimate <br /> development studio
109 </h1>
110 <p className="max-w-2xl text-base md:text-xl mt-8 dark:text-neutral-200">
111 We build beautiful products with the latest technologies and frameworks.
112 We are a team of passionate developers and designers that love to build
113 amazing products.
114 </p>
115 </div>
116 );
117};
118
119export const ProductCard = ({
120 product,
121 translate,
122}: {
123 product: {
124 title: string;
125 link: string;
126 thumbnail: string;
127 };
128 translate: MotionValue<number>;
129}) => {
130 return (
131 <motion.div
132 style={{
133 x: translate,
134 }}
135 whileHover={{
136 y: -20,
137 }}
138 key={product.title}
139 className="group/product h-96 w-[30rem] relative shrink-0"
140 >
141 <a
142 href={product.link}
143 className="block group-hover/product:shadow-2xl "
144 >
145 <img
146 src={product.thumbnail}
147 height="600"
148 width="600"
149 className="object-cover object-left-top absolute h-full w-full inset-0"
150 alt={product.title}
151 />
152 </a>
153 <div className="absolute inset-0 h-full w-full opacity-0 group-hover/product:opacity-80 bg-black pointer-events-none"></div>
154 <h2 className="absolute bottom-4 left-4 opacity-0 group-hover/product:opacity-100 text-white">
155 {product.title}
156 </h2>
157 </motion.div>
158 );
159};
160