Section 3D
Tall cards that fall back into 3D as the next one arrives.
Customize
<Section3d />Changes show live and stay in the address, so a link keeps them.
Code
"use client";
import { useEffect, useRef, type CSSProperties } from "react";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useGSAP } from "@gsap/react";
// A stack of tall photo cards that arrive one after another. The page pins a single stage; as you
// scroll, the next card rises from the bottom while the card under it fades, lifts and tips back
// into the screen, as if it were falling away into a room behind the page.
// One pin and one scrubbed timeline run the whole thing (the first version pinned every card on its
// own, which got heavy with a dozen cards). The animation is tied to the scrollbar, so it also
// plays backwards when you scroll up.
if (typeof window !== "undefined") gsap.registerPlugin(useGSAP, ScrollTrigger);
export type Section3DCard = {
/** The photo. */
image: string;
/** Alt text for the photo. Falls back to the name. */
imageAlt?: string;
/** A small label above the name, e.g. "01 / 08". */
number: string;
/** The big line on the card. */
name: string;
/** The line under the name. */
role: string;
/** A short quote at the bottom of the card. Leave it out for no quote. */
quote?: string;
};
export type Section3DProps = {
/** The cards, in the order they arrive. */
cards: Section3DCard[];
/** The big heading of the opening screen. */
introTitle?: string;
/** The paragraph under it. Pass an empty string to leave it out. */
introDescription?: string;
/** How far a card tips back while the next one arrives, in degrees. */
tilt?: number;
/** How far a card sinks away from you, in pixels. */
depth?: number;
/** How far a card rises while it recedes, as a percentage of its own height. */
lift?: number;
/** How much a receding card fades out, from 0 (stays solid) to 1 (fully gone). */
fade?: number;
/** Depth of the 3D effect, in pixels. Smaller is more dramatic. */
perspective?: number;
/** How much scrolling one hand-over takes, in screens. 1 moves the next card exactly with your scroll. */
scrollPerCard?: number;
/** The start colour of the heading underline and the small line on each card. */
accent?: string;
/** The end colour of those two gradients. */
accentEnd?: string;
/** The colour behind the cards. Use a dark one: the text on the page is light. */
backdrop?: string;
/** The scrolling element. Leave it out to use the page; give it a selector or an element for an inner scroller. */
scroller?: string | HTMLElement;
/** Extra classes for the outer wrapper. */
className?: string;
};
export function Section3D({
cards,
introTitle = "Portraits",
introDescription = "Eight photos in one stack. Scroll to bring the next one up.",
tilt = 80,
depth = 800,
lift = 25,
fade = 1,
perspective = 1000,
scrollPerCard = 1,
accent = "#ff6b35",
accentEnd = "#f7c59f",
backdrop = "#160f03",
scroller,
className = "",
}: Section3DProps) {
const rootRef = useRef<HTMLDivElement>(null);
const cardCount = cards.length;
// The motion settings are read by the tweens when they (re)measure, so dragging a slider in a
// playground doesn't rebuild the pin and throw the visitor back up the page
const settings = useRef({ tilt, depth, lift, fade, scrollPerCard });
settings.current = { tilt, depth, lift, fade, scrollPerCard };
const trigger = useRef<ScrollTrigger | null>(null);
useGSAP(
() => {
const root = rootRef.current;
if (!root || cardCount === 0) return;
const mm = gsap.matchMedia();
// Reduced motion: nothing is pinned or tipped. The cards are just a tall page, one after another.
mm.add("(prefers-reduced-motion: no-preference)", () => {
const stage = root.querySelector<HTMLElement>("[data-s3d-stage]");
const slots = gsap.utils.toArray<HTMLElement>("[data-s3d-slot]", root);
const faces = gsap.utils.toArray<HTMLElement>("[data-s3d-card]", root);
const line = root.querySelector<HTMLElement>("[data-s3d-line]");
if (!stage) return;
// Inside an inner scroller, "a screen" means that scroller's height, not the window's
const scrollEl = typeof scroller === "string" ? document.querySelector<HTMLElement>(scroller) : scroller;
const syncHeight = (): void => {
root.style.setProperty("--s3d-h", scrollEl ? `${scrollEl.clientHeight}px` : "100svh");
};
syncHeight();
ScrollTrigger.addEventListener("refreshInit", syncHeight);
// The slow light that runs down the line at the bottom of the opening screen
if (line) gsap.fromTo(line, { yPercent: -100 }, { yPercent: 100, duration: 2, ease: "sine.inOut", repeat: -1 });
// One timeline, one step per hand-over: card i+1 rises into view while card i falls back.
// Every step is one unit long and the steps run back to back, so scrub keeps them in order.
if (cardCount > 1) {
const handOvers = gsap.timeline({
defaults: { ease: "none", duration: 1 },
scrollTrigger: {
trigger: stage,
scroller,
start: "top top",
// Measured on every refresh, so rotating a phone or resizing the window stays correct
end: () => `+=${(cardCount - 1) * stage.offsetHeight * settings.current.scrollPerCard}`,
pin: true,
scrub: true,
anticipatePin: 1,
invalidateOnRefresh: true,
},
});
trigger.current = handOvers.scrollTrigger ?? null;
for (let i = 1; i < cardCount; i++) {
// The new card starts just below the stage (its slot sits at top: 100%) and climbs to the top
handOvers.fromTo(slots[i]!, { yPercent: 0 }, { yPercent: -100 }, i - 1);
handOvers.fromTo(
faces[i - 1]!,
{ opacity: 1, yPercent: 0, z: 0, rotationX: 0 },
{
opacity: () => 1 - settings.current.fade,
yPercent: () => -settings.current.lift,
z: () => -settings.current.depth,
rotationX: () => settings.current.tilt,
transformOrigin: "50% 50%",
force3D: true,
},
i - 1,
);
}
}
// A scroller that changes size (a resizable panel, for example) needs the pin measured again
let measure: gsap.core.Tween | undefined;
const observer = scrollEl ? new ResizeObserver(() => {
measure?.kill();
measure = gsap.delayedCall(0.2, () => ScrollTrigger.refresh());
}) : null;
if (scrollEl) observer?.observe(scrollEl);
return () => {
measure?.kill();
observer?.disconnect();
ScrollTrigger.removeEventListener("refreshInit", syncHeight);
trigger.current = null;
root.style.removeProperty("--s3d-h");
};
});
return () => mm.revert();
},
{ scope: rootRef, dependencies: [cardCount, scroller], revertOnUpdate: true },
);
// New motion settings: measure the pin again, keeping the scroll position
useEffect(() => {
trigger.current?.refresh();
}, [tilt, depth, lift, fade, scrollPerCard]);
const style = { backgroundColor: backdrop, "--s3d-h": "100svh" } as CSSProperties;
const gradient = `linear-gradient(90deg, ${accent}, ${accentEnd})`;
return (
<div ref={rootRef} className={`relative w-full overflow-x-clip text-white ${className}`} style={style}>
{/* The opening screen. It scrolls like a normal page. */}
<section className="flex h-[var(--s3d-h)] flex-col items-center justify-center px-6 text-center md:px-8">
<h2
className="mt-auto mb-6 bg-clip-text text-[clamp(48px,8vw,80px)] leading-[1.05] font-extrabold tracking-[-0.02em] text-transparent"
style={{ backgroundImage: `linear-gradient(135deg, ${accent} 0%, ${accentEnd} 50%, #fff 100%)` }}
>
{introTitle}
</h2>
{introDescription ? <p className="max-w-[500px] px-4 text-[clamp(16px,1.4vw,18px)] leading-normal tracking-[0.02em] text-white/50">{introDescription}</p> : null}
<div aria-hidden="true" className="relative mt-auto h-24 w-px overflow-hidden bg-white/10 md:h-48">
<span data-s3d-line className="absolute inset-0 block bg-gradient-to-b from-transparent via-white/60 to-transparent" />
</div>
</section>
{/* The stage that gets pinned. The cards sit stacked inside it. */}
<ul data-s3d-stage className="relative m-0 block h-[var(--s3d-h)] list-none overflow-hidden p-0 motion-reduce:h-auto motion-reduce:overflow-visible">
{cards.map((card, index) => (
<li
key={`${index}-${card.image}`}
data-s3d-slot
// The first card fills the stage; the others wait just below it. Reduced motion stacks them in the flow.
className={`absolute left-0 flex h-[var(--s3d-h)] w-full items-center justify-center p-4 md:p-8 motion-reduce:static motion-reduce:py-10 ${index === 0 ? "top-0" : "top-full"}`}
style={{ perspective, transformStyle: "preserve-3d" }}
>
<article
data-s3d-card
className="relative h-[80%] w-[92%] max-w-[500px] overflow-hidden rounded-2xl bg-black/40 md:w-1/2 md:max-w-[360px] md:min-w-[280px] md:rounded-[2rem] lg:w-[35%] lg:max-w-[500px] lg:min-w-[380px]"
style={{ willChange: "transform, opacity" }}
>
<img
src={card.image}
alt={card.imageAlt ?? card.name}
className="absolute inset-0 h-full w-full object-cover"
loading={index < 2 ? "eager" : "lazy"}
decoding="async"
draggable={false}
/>
<div className="absolute inset-0 flex flex-col justify-end bg-gradient-to-t from-black/90 via-black/40 via-30% to-transparent to-60% p-6 md:p-10">
<span className="mb-3 block text-[11px] font-semibold tracking-[0.3em] text-white/50 uppercase">{card.number}</span>
<h3 className="mb-2 text-[clamp(22px,2.2vw,32px)] leading-[1.1] font-extrabold tracking-[-0.02em] text-white">{card.name}</h3>
<p className="text-sm font-medium tracking-[0.05em] text-white/70 md:text-[15px]">{card.role}</p>
<div className="mt-4 h-[3px] w-10 rounded-full" style={{ backgroundImage: gradient }} />
{card.quote ? <p className="mt-4 text-xs leading-normal text-white/50 italic md:text-[13px]">“{card.quote}”</p> : null}
</div>
</article>
</li>
))}
</ul>
</div>
);
}
The component. Installs to components/dimaac/section-3d.tsx.
Install
With the shadcn CLI
npx shadcn@latest add https://ui.dimaac.com/r/section-3d.jsonIt adds components/dimaac/section-3d.tsx and installs what it imports. With the @dimaac namespace in components.json (Docs) it's just npx shadcn@latest add @dimaac/section-3d.
By hand
npm install gsap @gsap/react- Install the packages it uses: gsap, @gsap/react.
- Copy the component file below into components/dimaac/section-3d.tsx.
- It's styled with Tailwind v4 classes. If that folder sits outside the places Tailwind scans, add it with @source in your CSS.
- Import it with import { Section3d } from "@/components/dimaac/section-3d". Give its parent a size: it fills it.
Use with AI
Agent prompt
Paste it into Claude Code, Cursor or any coding agent, or open it straight in a chat. It carries your Customize settings.
Add the Section 3D component (<Section3d />) from DiMaac UI to this project.
Docs: https://ui.dimaac.com/components/section-3d
Source and dependencies (shadcn registry JSON): https://ui.dimaac.com/r/section-3d.json
Install it with:
npx shadcn@latest add https://ui.dimaac.com/r/section-3d.json
Then use it like this:
import { Section3d } from "@/components/dimaac/section-3d";
<Section3d />
If the shadcn CLI isn't set up here, fetch the registry JSON above, write files[0].content to components/dimaac/section-3d.tsx and install gsap, @gsap/react.
It uses Tailwind v4 classes, so make sure Tailwind scans that folder. Give its parent a size: it fills it. Keep light and dark mode working and keep its prefers-reduced-motion fallback.
Full index for agents: https://ui.dimaac.com/llms.txtFiles agents read
- llms.txt
- Every component and how to install it
- section-3d.md
- This page as Markdown: install, props and the full source
- section-3d.json
- The shadcn registry item
About
A scroll section for a team or an our-work list. The page pins one stage; as you scroll, the next tall photo card rises from the bottom while the card under it fades, lifts and tips back into the screen. One pin and one scrubbed timeline run the whole stack, so a dozen cards stay light, and the animation plays backwards when you scroll up. Tilt, depth, lift, fade, perspective and how much scrolling each hand-over takes are all props. It works on the page or inside any scrolling element through the scroller prop, re-measures when the window or the scroller changes size, uses plain img tags (no Next.js needed) and turns into an ordinary tall page of cards when the visitor prefers reduced motion. Ported from the first DiMaac UI, where every card was pinned on its own.
- Installs to
components/dimaac/section-3d.tsx- Uses
- gsap, @gsap/react
- Tags
- scrolltrigger, pin, 3d, cards, team
Portrait (Marcus Chen) by studiomiklus on Lummi (Lummi License). Portrait (Elena Voss) by Edita on Lummi (Lummi License). Portrait (Priya Nair) by Shaun Duval on Lummi (Lummi License). Portrait (Sofia Reyes) by SHIHO on Lummi (Lummi License). Portrait (Ava Mitchell) by Amino on Lummi (Lummi License). Portrait (Kai Tanaka) by Steph Meade on Lummi (Lummi License). Portrait (Liam Foster) by Lloyd Creates on Lummi (Lummi License). Portrait (Nina Patel) by Amino on Lummi (Lummi License).