← Components

Pin rotate sections

Pinned sections that turn in 3D.

Scroll · FreeInstall ↓
Open preview ↗
Loading the demoNew tab ↗

Customize

0.25
40 °
5.0 °
0.40
2200 px
#1a1a1a
Your code
<PinRotateSections children={children} />

Changes show live and stay in the address, so a link keeps them.

Code

"use client";

import { Children, useRef, type CSSProperties, type ReactNode } from "react";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useGSAP } from "@gsap/react";

// Full-screen sections that stack like a deck of cards. Each one pins to the top of the page, and
// while the next section slides up over it, the pinned one shrinks, tilts back and fades to dark,
// as if it were being pushed away. Four small pieces:
//   <PinRotateSections>  wraps everything and runs the animation
//   <PinRotateIntro> and <PinRotateOutro>  the plain dark openers and closers
//   <PinRotateSection>  one card in the stack. The animated ones are the sections.

if (typeof window !== "undefined") gsap.registerPlugin(useGSAP, ScrollTrigger);

export type PinRotateSectionsProps = {
  /** The intro, the sections and the outro, in order. Sections are found by <PinRotateSection>. */
  children: ReactNode;
  /** How much each section shrinks while it is pushed away. 0.25 ends at 75% of its size. */
  shrink?: number;
  /** How far each section tips back, in degrees. The direction alternates from card to card. */
  tilt?: number;
  /** How far each section turns in the page plane, in degrees. Also alternates. */
  twist?: number;
  /** How dark a pushed-away section gets, from 0 (not at all) to 1 (black). */
  dim?: number;
  /** Depth of the tilt, in pixels. Smaller is more dramatic. Below about 800 the corners can glitch. */
  perspective?: number;
  /** The colour that shows behind and around the shrinking sections. */
  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 PinRotateSections({
  children,
  shrink = 0.25,
  tilt = 40,
  twist = 5,
  dim = 0.4,
  perspective = 2200,
  backdrop = "#1a1a1a",
  scroller,
  className = "",
}: PinRotateSectionsProps) {
  const rootRef = useRef<HTMLDivElement>(null);
  // The effect has to start again when sections are added or removed
  const childCount = Children.count(children);

  useGSAP(
    () => {
      const root = rootRef.current;
      if (!root) return;

      const mm = gsap.matchMedia();

      // Reduced motion: no pinning and no tilting. The sections are just a normal page.
      mm.add("(prefers-reduced-motion: no-preference)", () => {
        const sections = gsap.utils.toArray<HTMLElement>("[data-pin-rotate-section]", root);
        const last = sections[sections.length - 1];
        if (!last) return;

        // The scroller can be a selector or an element: find the element once. A selector must be looked up
        // here, outside the scope, because the scope only searches inside this wrapper and the scroller is
        // always outside it. Using the element also lets us measure the scroller's height, not the window's.
        const scrollEl = (typeof scroller === "string" ? document.querySelector<HTMLElement>(scroller) : scroller) ?? undefined;
        // The height we measure sections against: the scroller's, or the window's
        const viewHeight = () => (scrollEl ? scrollEl.clientHeight : window.innerHeight);

        sections.forEach((section, index) => {
          const next = sections[index + 1];
          // The last card doesn't move: it is the one everything is pushed away by
          if (!next) return;

          const direction = index % 2 === 0 ? 1 : -1;
          const overlay = section.querySelector<HTMLElement>("[data-pin-rotate-overlay]");

          // Pin the card until the last one arrives, so the next card slides over the top of it.
          // A card taller than the screen (common on phones) pins by its bottom edge instead,
          // so its whole content gets read before it is covered.
          ScrollTrigger.create({
            trigger: section,
            scroller: scrollEl,
            start: () => (section.offsetHeight > viewHeight() ? "bottom bottom" : "top top"),
            endTrigger: last,
            end: "top top",
            pin: true,
            pinSpacing: false,
          });

          // While the next card climbs from the bottom edge to the top, the pinned card is pushed away.
          // scrub ties the animation to the scrollbar, so it runs back when you scroll up.
          const away = gsap.timeline({
            defaults: { ease: "none" },
            scrollTrigger: { trigger: next, scroller: scrollEl, start: "top bottom", end: "top top", scrub: true },
          });
          away.to(section, { scale: 1 - shrink, rotation: direction * twist, rotationX: direction * tilt, transformPerspective: perspective || 0, force3D: true }, 0);
          if (overlay) away.to(overlay, { opacity: dim }, 0);
        });

        // Pictures arriving late change the page height, so measure the pins again.
        // A short delay turns a burst of loads into one measurement.
        let measure: gsap.core.Tween | undefined;
        const observer = new ResizeObserver(() => {
          measure?.kill();
          measure = gsap.delayedCall(0.2, () => ScrollTrigger.refresh());
        });
        // Only the wrapper: a pinned card changes its own box while it sticks, which must not re-trigger this
        observer.observe(root);

        return () => {
          measure?.kill();
          observer.disconnect();
        };
      });

      return () => mm.revert();
    },
    { scope: rootRef, dependencies: [childCount, shrink, tilt, twist, dim, perspective, scroller], revertOnUpdate: true },
  );

  return (
    <div ref={rootRef} className={`relative w-full overflow-x-clip ${className}`} style={{ backgroundColor: backdrop }}>
      {children}
    </div>
  );
}

export type PinRotateIntroProps = {
  /** The opening words: usually a heading and a paragraph. */
  children: ReactNode;
  /** Extra classes: change the colours, the height or the padding here. */
  className?: string;
};

/** A full-height dark opener. It scrolls normally. */
export function PinRotateIntro({ children, className = "" }: PinRotateIntroProps) {
  return (
    <section data-pin-rotate-intro className={`flex min-h-[100svh] flex-col items-center justify-center bg-[#1a1a1a] px-[6vw] text-center text-white md:px-[8vw] ${className}`}>
      {children}
    </section>
  );
}

export type PinRotateSectionProps = {
  /** What the card shows. */
  children: ReactNode;
  /** Extra classes: the background, text colour and padding. Cards are paper-coloured by default. */
  className?: string;
  /** Inline styles for the card, e.g. a background image. */
  style?: CSSProperties;
};

/** One card of the stack. It pins, then shrinks and darkens as the next card covers it. */
export function PinRotateSection({ children, className = "", style }: PinRotateSectionProps) {
  return (
    <section
      data-pin-rotate-section
      className={`relative flex min-h-[85svh] flex-col bg-[#fcfcfc] px-[6vw] py-[5vh] text-[#1a1a1a] md:flex-row md:justify-between md:px-[8vw] md:py-[10vh] ${className}`}
      style={{ borderBottom: "1px solid rgba(0,0,0,0.24)", willChange: "transform", transformStyle: "flat", ...style }}
    >
      {children}
      {/* The shadow that grows over the card as it is pushed away */}
      <div data-pin-rotate-overlay aria-hidden="true" className="pointer-events-none absolute inset-0 bg-black opacity-0 [backface-visibility:hidden]" />
    </section>
  );
}

export type PinRotateOutroProps = {
  /** The closing words. */
  children: ReactNode;
  /** Extra classes: change the colours, the height or the padding here. */
  className?: string;
};

/** A full-height dark closer. The last card slides up over the stack and ends on this. */
export function PinRotateOutro({ children, className = "" }: PinRotateOutroProps) {
  return (
    <section data-pin-rotate-outro className={`relative flex min-h-[100svh] flex-col items-center justify-center bg-[#1a1a1a] px-[6vw] text-center text-white md:px-[8vw] ${className}`}>
      {children}
    </section>
  );
}

The component. Installs to components/dimaac/pin-rotate-sections.tsx.

Install

With the shadcn CLI

npx shadcn@latest add https://ui.dimaac.com/r/pin-rotate-sections.json

It adds components/dimaac/pin-rotate-sections.tsx and installs what it imports. With the @dimaac namespace in components.json (Docs) it's just npx shadcn@latest add @dimaac/pin-rotate-sections.

By hand

npm install gsap @gsap/react
  1. Install the packages it uses: gsap, @gsap/react.
  2. Copy the component file below into components/dimaac/pin-rotate-sections.tsx.
  3. It's styled with Tailwind v4 classes. If that folder sits outside the places Tailwind scans, add it with @source in your CSS.
  4. Import it with import { PinRotateSections } from "@/components/dimaac/pin-rotate-sections". Give its parent a size: it fills it.

Props

PropTypeDefaultDescription
children (required)ReactNode-The intro, the sections and the outro, in order. Sections are found by <PinRotateSection>.
shrinknumber0.25How much each section shrinks while it is pushed away. 0.25 ends at 75% of its size.
tiltnumber40How far each section tips back, in degrees. The direction alternates from card to card.
twistnumber5How far each section turns in the page plane, in degrees. Also alternates.
dimnumber0.4How dark a pushed-away section gets, from 0 (not at all) to 1 (black).
perspectivenumber2200Depth of the tilt, in pixels. Smaller is more dramatic. Below about 800 the corners can glitch.
backdropstring"#1a1a1a"The colour that shows behind and around the shrinking sections.
scrollerstring | HTMLElement-The scrolling element. Leave it out to use the page; give it a selector or an element for an inner scroller.
classNamestring""Extra classes for the outer wrapper.

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.

Prompt
Add the Pin rotate sections component (<PinRotateSections />) from DiMaac UI to this project.

Docs: https://ui.dimaac.com/components/pin-rotate-sections
Source and dependencies (shadcn registry JSON): https://ui.dimaac.com/r/pin-rotate-sections.json

Install it with:
npx shadcn@latest add https://ui.dimaac.com/r/pin-rotate-sections.json

Then use it like this:
import { PinRotateSections } from "@/components/dimaac/pin-rotate-sections";
<PinRotateSections children={children} />

If the shadcn CLI isn't set up here, fetch the registry JSON above, write files[0].content to components/dimaac/pin-rotate-sections.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.txt

Files agents read

llms.txt
Every component and how to install it
pin-rotate-sections.md
This page as Markdown: install, props and the full source
pin-rotate-sections.json
The shadcn registry item

About

A stack of full-screen sections. Each one pins to the top of the page, and while the next section slides up over it the pinned one shrinks, tips back in 3D, turns a few degrees and fades to dark, like a deck of cards being pushed away. The tilt alternates left and right from card to card. The animation is scrubbed to the scrollbar, so it runs back when you scroll up. It works on the page or inside any scrolling element through the scroller prop, handles cards taller than the screen on phones, measures again when pictures load, and falls back to an ordinary page with every section visible when the visitor prefers reduced motion. Four small parts: PinRotateSections, PinRotateIntro, PinRotateSection and PinRotateOutro.

Installs to
components/dimaac/pin-rotate-sections.tsx
Uses
gsap, @gsap/react
Tags
scrolltrigger, pin, 3d, sections, scrub

Concrete Corner by Ricardo Matos on Lummi (Lummi License). Balcony Study by Mariate on Lummi (Lummi License). The Red Wall by Siren Media on Lummi (Lummi License). White Corner by Mikiwa on Lummi (Lummi License). Palm Court by Binks AI on Lummi (Lummi License).