Circular Scatter Code
Circular loop scatter animation where cards stack one-by-one at screen center, then scatter to the outer edges with hero text centered.
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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
"use client";
import { useGSAP } from "@gsap/react";
import gsap from "gsap";
import Image from "next/image";
import { useEffect, useRef, useState } from "react";
gsap.registerPlugin(useGSAP);
// Custom Text Scramble Component
function ScrambleText({
text,
speed = 25,
delay = 0,
}: {
text: string;
speed?: number;
delay?: number;
}) {
const [displayText, setDisplayText] = useState("");
const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@#$%&*";
useEffect(() => {
let timer: NodeJS.Timeout;
let frame = 0;
const finalLength = text.length;
const run = () => {
timer = setTimeout(() => {
let current = "";
for (let i = 0; i < finalLength; i++) {
if (i < frame / 3) {
current += text[i];
} else {
current += chars[Math.floor(Math.random() * chars.length)];
}
}
setDisplayText(current);
frame++;
if (frame / 3 < finalLength) {
run();
} else {
setDisplayText(text);
}
}, speed);
};
const delayTimer = setTimeout(run, delay);
return () => {
clearTimeout(timer);
clearTimeout(delayTimer);
};
}, [text, speed, delay]);
return <span>{displayText}</span>;
}
const talentData = [
{
id: 0,
img: "/Untitled design.png",
name: "Sarah Jenkins",
role: "iOS Tech Lead",
color: "#f1b333", // Gold
left: "6vw",
top: "14vh",
rot: -12,
},
{
id: 1,
img: "/Untitled design (1).png",
name: "Alex Rivera",
role: "Android Architect",
color: "#0c9367", // Green
left: "4vw",
top: "44vh",
rot: 8,
},
{
id: 2,
img: "/Untitled design (2).png",
name: "Elena Rostova",
role: "SwiftUI Lead",
color: "#8b5cf6", // Purple
left: "7vw",
top: "74vh",
rot: -6,
},
{
id: 3,
img: "/Untitled design (3).png",
name: "Marcus Vance",
role: "Flutter Specialist",
color: "#3b82f6", // Blue
left: "26vw",
top: "10vh",
rot: 6,
},
{
id: 4,
img: "/Untitled design (4).png",
name: "Siddharth Mehta",
role: "React Native Lead",
color: "#c53b3a", // Red
left: "58vw",
top: "10vh",
rot: -8,
},
{
id: 5,
img: "/Untitled design (5).png",
name: "Chloe Dupont",
role: "KMP Engineer",
color: "#eab308", // Yellow
left: "80vw",
top: "14vh",
rot: 10,
},
{
id: 6,
img: "/Untitled design (6).png",
name: "Liam O'Connor",
role: "iOS UI Specialist",
color: "#06b6d4", // Cyan
left: "83vw",
top: "44vh",
rot: -10,
},
{
id: 7,
img: "/Untitled design (7).png",
name: "Sofia Giraldo",
role: "Mobile DevOps Lead",
color: "#ec4899", // Pink
left: "76vw",
top: "74vh",
rot: 12,
},
];
export default function CircularScatterPage() {
const containerRef = useRef<HTMLDivElement>(null);
const heroRef = useRef<HTMLDivElement>(null);
const floatingCardsRef = useRef<HTMLDivElement>(null);
const floatTimelineRef = useRef<gsap.core.Timeline | null>(null);
useGSAP(
() => {
const cards = gsap.utils.toArray<HTMLElement>(".scatter-card");
// Compute all coordinates relative to screen center while cards are in their initial CSS positions
const cardParams = cards.map((card) => {
const rect = card.getBoundingClientRect();
const targetCenterX = rect.left + rect.width / 2;
const screenCenterX = window.innerWidth / 2;
const targetCenterY = rect.top + rect.height / 2;
const screenCenterY = window.innerHeight / 2;
const X_c = screenCenterX - targetCenterX;
const Y_c = screenCenterY - targetCenterY;
const R_final = Math.sqrt(X_c * X_c + Y_c * Y_c);
const theta_final = Math.atan2(-Y_c, -X_c);
return {
card,
X_c,
Y_c,
R_final,
theta_final,
};
});
// 1. Initial State: Centered and Stacked
cardParams.forEach((param, idx) => {
gsap.set(param.card, {
x: param.X_c,
y: param.Y_c,
scale: 0.9,
rotation: 0,
opacity: 0,
zIndex: 10 + idx,
});
});
const introTl = gsap.timeline({
defaults: { ease: "power4.out" },
onComplete: () => {
startFloatingIdle();
},
});
// Staggered Stack-in at Center:
// Cards appear one-by-one in the exact center of the screen
talentData.forEach((card, idx) => {
introTl.to(
`.scatter-card-${idx}`,
{
opacity: 1,
scale: 1.02,
rotation: idx % 2 === 0 ? 4 : -4,
duration: 0.38,
ease: "back.out(1.2)",
},
idx * 0.3,
);
});
const scatterStart = talentData.length * 0.3 + 0.4;
// Explode to Circular Layout with Spiral Orbit:
// Cards explode outwards following a circular loop/spiral path before stopping
cardParams.forEach((param, idx) => {
const loops = 0.6; // Elegant 0.6 circular loop before stopping to keep it clean and non-overlapping
const animObj = { p: 0 };
introTl.to(
animObj,
{
p: 1,
duration: 2.8,
ease: "power3.out",
onUpdate: () => {
const t = animObj.p;
const R_t = param.R_final * t;
// Spiral: starts at theta_final - 2*PI*loops, ends at theta_final
const theta_t = param.theta_final - 2 * Math.PI * (1 - t) * loops;
const x = param.X_c + R_t * Math.cos(theta_t);
const y = param.Y_c + R_t * Math.sin(theta_t);
gsap.set(param.card, {
x,
y,
rotation: gsap.utils.interpolate(
idx % 2 === 0 ? 4 : -4,
talentData[idx].rot,
t,
),
scale: gsap.utils.interpolate(1.02, 1, t),
});
},
},
scatterStart,
); // Start all card expansions simultaneously to prevent intersections and keep the movement clean
});
// Fade/Slide in the Central Hero text at the same time
introTl
.fromTo(
".hero-tagline",
{ y: 30, opacity: 0 },
{ y: 0, opacity: 1, duration: 1.2 },
scatterStart,
)
.fromTo(
".hero-title-scramble",
{ opacity: 0 },
{ opacity: 1, duration: 0.8 },
scatterStart + 0.2,
)
.fromTo(
".hero-subtitle",
{ y: 30, opacity: 0 },
{ y: 0, opacity: 1, duration: 1.2 },
scatterStart + 0.4,
)
.fromTo(
".hero-cta-btn",
{ y: 30, opacity: 0 },
{ y: 0, opacity: 1, duration: 1.2 },
scatterStart + 0.6,
);
// 2. Continuous Floating Idle Loop
function startFloatingIdle() {
floatTimelineRef.current = gsap.timeline({ repeat: -1 });
cardParams.forEach((param, idx) => {
const offset = idx % 2 === 0 ? 1 : -1;
gsap.to(param.card, {
y: `+=${10 * offset}`,
x: `+=${5 * -offset}`,
rotation: `+=${1.5 * offset}`,
duration: 3.2 + idx * 0.3,
yoyo: true,
repeat: -1,
ease: "sine.inOut",
});
});
}
return () => {
if (floatTimelineRef.current) floatTimelineRef.current.kill();
};
},
{ scope: containerRef },
);
// Custom mouse-move/hover functions for cards
const handleCardEnter = (
e: React.MouseEvent<HTMLDivElement>,
color: string,
) => {
gsap.to(e.currentTarget, {
scale: 1.08,
borderColor: color,
boxShadow: `0 15px 35px ${color}20, 6px 6px 0px #2a2a2a`,
duration: 0.3,
overwrite: "auto",
});
gsap.to(e.currentTarget.querySelector(".card-role-text"), {
color: color,
duration: 0.3,
});
};
const handleCardLeave = (e: React.MouseEvent<HTMLDivElement>) => {
gsap.to(e.currentTarget, {
scale: 1,
borderColor: "#2a2a2a",
boxShadow: "4px 4px 0px #2a2a2a",
duration: 0.3,
overwrite: "auto",
});
gsap.to(e.currentTarget.querySelector(".card-role-text"), {
color: "#a1a1aa",
duration: 0.3,
});
};
return (
<div
className="relative h-screen w-screen bg-[#f2ece0] text-[#2a2a2a] overflow-hidden selection:bg-[#f1b333] selection:text-black"
ref={containerRef}
>
{/* Premium subtle grid background overlay */}
<div
className="absolute inset-0 dot-grid pointer-events-none z-0"
style={{ opacity: 0.25 }}
/>
{/* 1. Hero Section (Circular Cards Workspace) */}
<div
ref={heroRef}
className="h-screen w-full relative flex flex-col justify-center items-center overflow-hidden"
>
{/* Central Hero Text Area (Bottom Centered) */}
<div className="absolute bottom-[4vh] md:bottom-[6vh] left-1/2 -translate-x-1/2 z-20 text-center w-full max-w-2xl px-6 pointer-events-none">
<span className="hero-tagline inline-block font-mono text-[9px] tracking-[0.2em] uppercase text-[#f1b333] font-black bg-[#2a2a2a] text-white px-3 py-1 rounded-full mb-4">
Vetted Mobile Engineers
</span>
<h1 className="hero-title-scramble font-serif font-black text-4xl md:text-6xl text-[#2a2a2a] leading-[1.05] tracking-tighter uppercase mb-4">
<ScrambleText text="Hire Mobile Devs" delay={2800} />
<br />
<span className="text-[#f1b333]">
<ScrambleText text="Differently" delay={3400} />
</span>
</h1>
<p className="hero-subtitle font-mono text-[11px] md:text-xs text-[#2a2a2a]/70 max-w-lg mx-auto leading-relaxed mb-8 pointer-events-auto">
Engineers who own outcomes — CTO-screened with a ≤ 5% pass rate.
Ready to scale your product immediately.
</p>
<div className="hero-cta-btn inline-block pointer-events-auto">
<button
onClick={() =>
window.history.length > 1
? window.history.back()
: (window.location.href = "/")
}
className="brutalist-btn bg-[#2a2a2a] text-white hover:bg-black px-8 py-3.5 rounded-full font-mono text-[11px] font-bold uppercase border-2 border-[#2a2a2a] shadow-[4px_4px_0px_#f1b333] cursor-pointer transition-transform duration-150 active:translate-y-0.5"
>
← Back
</button>
</div>
</div>
{/* Floating cards container */}
<div
ref={floatingCardsRef}
className="absolute inset-0 w-full h-full pointer-events-none z-10"
>
{talentData.map((card, idx) => (
<div
key={card.id}
className={`scatter-card scatter-card-${idx} absolute w-[36vw] md:w-[13.5vw] aspect-[3/4] pointer-events-auto select-none rounded-3xl border-2 border-[#2a2a2a] bg-white p-3 shadow-[4px_4px_0px_#2a2a2a] cursor-pointer transition-shadow duration-200`}
style={{
left: card.left,
top: card.top,
}}
onMouseEnter={(e) => handleCardEnter(e, card.color)}
onMouseLeave={handleCardLeave}
>
{/* Card Image Area */}
<div className="w-full h-[70%] bg-[#fcfbfa] border border-[#2a2a2a]/10 rounded-2xl overflow-hidden relative">
<Image
src={card.img}
alt={card.name}
fill
priority
unoptimized
className="object-cover"
/>
</div>
{/* Card Title Details */}
<div className="h-[30%] flex flex-col justify-end pt-2">
<h4 className="font-serif font-black text-xs md:text-sm text-[#2a2a2a] leading-none mb-1 truncate">
{card.name}
</h4>
<div className="flex justify-between items-center w-full">
<span className="card-role-text font-mono text-[8px] md:text-[9px] text-zinc-400 font-bold uppercase">
{card.role}
</span>
<span className="font-mono text-[7px] text-zinc-400/80">
[0{idx + 1}]
</span>
</div>
</div>
</div>
))}
</div>
</div>
</div>
);
}
⚙️ Setup & Integration Guide
How to install, import, and configure this animation in your project
Option A: Install via CLI (Recommended)
You can install this component directly into your project via the TweenLabs CLI. It automatically creates the file and configures dependencies:
Option B: Manual Installation
Follow these steps to integrate the component into your project manually:
Install Packages
First, install GSAP and its official React hook helper library (@gsap/react).
Add Required CSS Styles
Copy the styles from the Required CSS tab above, or open the styles.css file that was automatically downloaded with your component. Paste these classes into your global stylesheet (e.g. src/app/globals.css or similar).
Create Component File
Create a new file in your React or Next.js project (e.g. src/components/CircularScatter.tsx) and paste the code from the Standalone React Component tab above. If no standalone tab is available, copy the full page file code and adjust the routing logic for your needs.
Import & Render
Import and render the component in your page or view layout:
import CircularScatter from "@/components/CircularScatter";
export default function Page() {
return (
<main className="min-h-screen p-8 bg-[#f5f5f5] flex items-center justify-center">
<CircularScatter />
</main>
);
}Customization & Component Properties
🛠️ Customization & Component Properties (Props)
You can pass the following settings to configure the layout and animation details:
cards(Array): A list of circular scatter card datasets.