Spaces:
Sleeping
Sleeping
File size: 11,313 Bytes
a72140d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | "use client";
import { animate } from "motion";
import { useEffect, useRef, useState } from "react";
import CurvyRect from "@/components/shared/layout/curvy-rect";
import { sleep } from "@/utils/sleep";
import BrowserMobile from "./_svg/BrowserMobile";
import BrowserTab from "./_svg/BrowserTab";
import HeroScrapingCode from "./Code/Code";
import HeroScrapingTag from "./Tag/Tag";
import "./HeroScraping.css";
export default function HeroScraping() {
const [step, setStep] = useState(-1);
const navigationRef = useRef<HTMLDivElement>(null);
const buttonRef = useRef<HTMLDivElement>(null);
const h1Ref = useRef<HTMLDivElement>(null);
const descriptionRef = useRef<HTMLDivElement>(null);
const ctaRef = useRef<HTMLDivElement>(null);
const highlightRef = useRef<HTMLDivElement>(null);
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const wrapElement = async (
element: HTMLElement,
{ borderRadius }: { borderRadius?: number } = {},
) => {
if (!containerRef.current) return;
const containerBnds = containerRef.current.getBoundingClientRect();
const elementBnds = element.getBoundingClientRect();
if (!highlightRef.current) return;
try {
if (highlightRef.current) {
await animate(highlightRef.current, { opacity: 0 }, { duration: 0.3 });
}
} catch (error) {
console.error("Error animating highlight:", error);
}
if (!highlightRef.current) return;
Object.assign(highlightRef.current.style, {
left: elementBnds.left - containerBnds.left - 4 + "px",
top: elementBnds.top - containerBnds.top - 4 + "px",
width: elementBnds.width + 8 + "px",
height: elementBnds.height + 8 + "px",
borderRadius: borderRadius ? `${borderRadius}px` : undefined,
});
try {
await animate(
highlightRef.current,
{ opacity: [1, 0.5, 0.3, 0.8, 0.6, 0.9, 0.7, 1] },
{ duration: 0.4 },
);
} catch (error) {
console.error("Error animating highlight:", error);
}
};
const start = async () => {
setStep(0);
if (!highlightRef.current) return;
await animate(highlightRef.current, {
scale: 1,
opacity: 1,
});
await sleep(700);
setTimeout(() => setStep(1), 300);
if (navigationRef.current) {
await wrapElement(navigationRef.current);
}
await sleep(1200);
setTimeout(() => setStep(2), 300);
if (buttonRef.current) {
await wrapElement(buttonRef.current);
}
await sleep(1200);
setTimeout(() => setStep(3), 300);
if (h1Ref.current) {
await wrapElement(h1Ref.current, { borderRadius: 12 });
}
await sleep(1200);
setTimeout(() => setStep(4), 300);
if (descriptionRef.current) {
await wrapElement(descriptionRef.current, { borderRadius: 8 });
}
await sleep(1200);
setTimeout(() => setStep(5), 300);
if (ctaRef.current) {
await wrapElement(ctaRef.current, { borderRadius: 24 });
}
await sleep(1500);
setTimeout(() => setStep(6), 300);
if (highlightRef.current) {
await animate(highlightRef.current, { opacity: 0 }, { duration: 0.3 });
}
};
let started = false;
const onScroll = () => {
if (started) return;
if (window.scrollY > 100) {
started = true;
start();
window.removeEventListener("scroll", onScroll);
}
};
setTimeout(() => {
if (started) return;
started = true;
start();
window.removeEventListener("scroll", onScroll);
}, 2000);
window.addEventListener("scroll", onScroll);
return () => window.removeEventListener("scroll", onScroll);
}, []);
return (
<div
className="pt-56 lg:pt-25 lg:px-25 container -mt-36 relative"
ref={containerRef}
>
<div className="h-53 absolute top-[calc(100%-1px)] w-full left-0">
<div className="h-1 bg-border-faint bottom-0 left-0 w-full absolute" />
</div>
<div
className="left-61 top-89 rounded-[16px] size-32 absolute hero-scraping-highlight inside-border before:border-border-loud opacity-0 scale-[0.9]"
ref={highlightRef}
/>
<div className="overlay lg-max:hidden">
<div className="h-1 absolute bottom-0 w-full left-0 bg-border-faint" />
<CurvyRect className="overlay" bottom />
</div>
<div className="lg:h-370 rounded-t-16 lg-max:pt-70 relative">
<div className="overlay mask-border lg-max:hidden p-1 bg-gradient-to-b from-black/7 to-transparent" />
<div className="top-17 left-17 flex gap-8 items-center absolute lg-max:hidden">
{Array.from({ length: 3 }).map((_, index) => (
<div
className="w-10 h-10 rounded-full relative inside-border before:border-border-muted"
key={index}
/>
))}
</div>
<div className="pt-42 lg:px-6">
<BrowserMobile className="absolute top-0 cw-316 lg:hidden" />
<BrowserTab className="absolute top-[7.5px] left-70 lg-max:hidden bg-background-base z-[1]" />
<div className="absolute size-18 top-17 left-89 lg-max:hidden inside-border before:border-border-muted z-[2] rounded-full" />
<div className="rounded-t-16 relative lg:h-330 lg:p-6">
<div className="overlay mask-border lg-max:hidden p-1 bg-gradient-to-b from-black/7 to-transparent" />
<div className="lg:h-322 rounded-t-10 relative">
<div className="overlay mask-border lg-max:hidden p-1 bg-gradient-to-b z-[2] from-black/7 to-transparent" />
<div className="px-28 lg-max:hidden py-20 flex justify-between items-center relative border-b border-border-faint">
<div className="flex gap-8 items-center relative">
<div className="size-24 rounded-full relative inside-border before:border-border-muted" />
<div className="w-64 h-12 rounded-full relative inside-border before:border-border-muted" />
{step >= 0 && (
<HeroScrapingTag
active={step === 0}
className="absolute left-[calc(100%+24px)] top-0"
initial={{ x: -12, opacity: 0 }}
label="Logo"
/>
)}
</div>
<div
className="absolute top-24 center-x flex gap-8"
ref={navigationRef}
>
{step >= 1 && (
<HeroScrapingTag
active={step === 1}
className="absolute right-[calc(100%+20px)] -top-4"
initial={{ x: 12, opacity: 0 }}
label="Navigation"
/>
)}
{Array.from({ length: 4 }).map((_, index) => (
<div
className="w-64 h-16 rounded-full relative inside-border before:border-border-muted"
key={index}
/>
))}
</div>
<div
className="w-72 h-24 rounded-full relative inside-border before:border-border-muted"
ref={buttonRef}
>
{step >= 2 && (
<HeroScrapingTag
active={step === 2}
className="absolute right-[calc(100%+20px)] top-0"
initial={{ x: 12, opacity: 0 }}
label="Button"
/>
)}
</div>
</div>
<div className="lg:grid grid-cols-2">
<div className="pt-40 pl-151 flex gap-16 relative lg-max:hidden">
<CurvyRect
className="size-32 -top-1 -right-1 absolute"
topRight
/>
<div className="h-53 lg-max:hidden -left-37 bottom-1 absolute w-65">
<CurvyRect className="overlay" left />
</div>
<div>
<div
className="flex gap-16 mb-16 flex-wrap w-300 relative"
ref={h1Ref}
>
{step >= 3 && (
<HeroScrapingTag
active={step === 3}
className="absolute right-[calc(100%+16px)] top-0"
initial={{ x: 12, opacity: 0 }}
label="H1 Title"
/>
)}
<div className="w-144 h-32 rounded-8 relative inside-border before:border-border-muted" />
<div className="w-82 h-32 rounded-8 relative inside-border before:border-border-muted" />
<div className="w-100 h-32 rounded-8 relative inside-border before:border-border-muted" />
<div className="w-180 h-32 rounded-8 relative inside-border before:border-border-muted" />
</div>
<div
className="flex gap-6 mb-32 flex-wrap w-300 relative"
ref={descriptionRef}
>
{step >= 4 && (
<HeroScrapingTag
active={step === 4}
className="absolute top-0 right-[calc(100%+16px)]"
initial={{ x: 12, opacity: 0 }}
label="Description"
/>
)}
<div className="w-131 h-10 rounded-full relative inside-border before:border-border-muted" />
<div className="w-72 h-10 rounded-full relative inside-border before:border-border-muted" />
<div className="w-34 h-10 rounded-full relative inside-border before:border-border-muted" />
<div className="w-56 h-10 rounded-full relative inside-border before:border-border-muted" />
<div className="w-116 h-10 rounded-full relative inside-border before:border-border-muted" />
<div className="w-116 h-10 rounded-full relative inside-border before:border-border-muted" />
</div>
<div
className="w-64 h-24 rounded-full relative inside-border before:border-border-muted"
ref={ctaRef}
>
{step >= 5 && (
<HeroScrapingTag
active={step === 5}
className="absolute top-0 right-[calc(100%+16px)]"
initial={{ x: 12, opacity: 0 }}
label="CTA Button"
/>
)}
</div>
</div>
</div>
<HeroScrapingCode step={step} />
</div>
</div>
</div>
</div>
</div>
</div>
);
}
|