← Components

Images flow

Images spread from the centre into 3D.

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

Customize

0.70
10 screens
0.81
4.0
2000 px
500 px
350 px
0.40
#e9e9e9
#1c1c1c
#1c1c1c
Your code
<ImagesFlow
  images={images}
  introTitle={introTitle}
  outroTitle={outroTitle}
/>

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";

// An intro title, then a pinned "tunnel" where photos explode out of the middle of the screen toward
// the camera as you scroll, then an outro title. The flow section pins to the screen and the
// scrollbar drives every photo: scroll down and they fly out, scroll up and they fly back in.
// The last image in the list is different: it is the full-screen backdrop that grows in behind the rest.
//
// Fonts: the demo uses Raleway for the titles and Instrument Serif for the flow text. Load them, or set
// the CSS variables --images-flow-title-font and --images-flow-flow-font to use your own.

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

export type ImagesFlowImage = {
  /** Where the picture lives. */
  src: string;
  /** What it shows. Leave it empty for a purely decorative picture (the default). */
  alt?: string;
};

export type ImagesFlowProps = {
  /** The pictures. The last one is the full-screen backdrop, the others fly past. Twelve to thirty look best. */
  images: (string | ImagesFlowImage)[];
  /** The big word before the flow starts. */
  introTitle: string;
  /** A line under the intro title. */
  introSubtitle?: string;
  /** The text that stays in the middle of the screen while the pictures fly. Use a line break for two lines. */
  flowText?: string;
  /** The big word after the flow ends. */
  outroTitle: string;
  /** A line under the outro title. */
  outroSubtitle?: string;
  /** How far the pictures spread sideways on a wide screen. 0.7 puts the outermost ones at 70% of the screen away from the middle. */
  spread?: number;
  /** The same, on a screen narrower than 800px, where the pictures need to travel further to leave the frame. */
  mobileSpread?: number;
  /** How long the flow takes, in screens of scrolling. */
  scrollLength?: number;
  /** How much of the scroll the start times of the pictures are spread over, from 0 (all leave together) to 0.9. */
  stagger?: number;
  /** How fast a picture flies, as a multiple of the whole scroll. 4 means one picture needs a quarter of the scroll. */
  flightSpeed?: number;
  /** Depth of the 3D scene in pixels. Pictures vanish as they pass this distance. Smaller is more dramatic. */
  perspective?: number;
  /** Width of each flying picture, in pixels. On a narrow screen it never goes wider than 90% of it. */
  cardWidth?: number;
  /** Height of each flying picture, in pixels. */
  cardHeight?: number;
  /** How dark the full-screen backdrop is, from 0 (not at all) to 1 (black). */
  dim?: number;
  /** Background of the intro and the outro. */
  pageColor?: string;
  /** Colour of the intro and outro text. */
  inkColor?: string;
  /** Background of the flow section, behind the pictures. */
  stageColor?: string;
  /** The tag of the two big titles: use "h1" if this is the main heading of your page. */
  titleAs?: "h1" | "h2" | "h3";
  /** 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;
};

// Where each picture ends up, as a fraction of the screen (-1 left/top to 1 right/bottom).
// A hand-picked scatter, so no two neighbours fly the same way.
const SCATTER = [
  [-0.8, -0.6], [0.7, 0.4], [-0.5, 0.7], [0.6, -0.5], [-0.8, 0.2], [0.8, -0.3], [-0.6, -0.8],
  [0.4, 0.6], [-0.7, 0.5], [0.5, -0.7], [-0.4, -0.4], [0.3, 0.8], [-0.8, 0.3], [0.6, 0.2],
  [-0.2, -0.7], [0.7, -0.6], [-0.5, 0.4], [0.4, -0.4], [-0.6, 0.6], [0.8, 0.5], [-0.3, -0.5],
  [0.5, 0.3], [-0.7, -0.2], [0.2, 0.7], [-0.4, 0.8], [0.6, -0.8], [-0.8, 0.1],
] as const;

/** The target for picture number `index`. Past the hand-picked list it follows a fixed spiral, never random. */
function scatterAt(index: number): { x: number; y: number } {
  const picked = SCATTER[index];
  if (picked) return { x: picked[0], y: picked[1] };
  const angle = index * 2.399963; // the golden angle, so neighbours never line up
  const radius = 0.35 + 0.5 * ((index * 0.618) % 1);
  return { x: Math.cos(angle) * radius, y: Math.sin(angle) * radius };
}

export function ImagesFlow({
  images,
  introTitle,
  introSubtitle,
  flowText = "Twenty-eight photos,\none scroll",
  outroTitle,
  outroSubtitle,
  spread = 0.7,
  mobileSpread = 1.5,
  scrollLength = 10,
  stagger = 0.81,
  flightSpeed = 4,
  perspective = 2000,
  cardWidth = 500,
  cardHeight = 350,
  dim = 0.4,
  pageColor = "#e9e9e9",
  inkColor = "#1c1c1c",
  stageColor = "#1c1c1c",
  titleAs: Heading = "h2",
  scroller,
  className = "",
}: ImagesFlowProps) {
  const rootRef = useRef<HTMLDivElement>(null);
  const flowRef = useRef<HTMLElement>(null);
  const cardRefs = useRef<(HTMLDivElement | null)[]>([]);

  // These change how the pictures are placed, not how the scroll is wired up. The animation reads
  // them on every frame, so moving a slider doesn't rebuild the pin.
  const live = useRef({ spread, mobileSpread, stagger, flightSpeed, perspective });
  live.current = { spread, mobileSpread, stagger, flightSpeed, perspective };
  // Draws the pictures for the current scroll position. Set by the effect below.
  const redraw = useRef<(() => void) | null>(null);
  useEffect(() => {
    redraw.current?.();
  }, [spread, mobileSpread, stagger, flightSpeed, perspective]);

  const items = images.map((image) => (typeof image === "string" ? { src: image, alt: "" } : { src: image.src, alt: image.alt ?? "" }));
  const lastIndex = items.length - 1;

  useGSAP(
    () => {
      const root = rootRef.current;
      const flow = flowRef.current;
      const cards = cardRefs.current.slice(0, items.length).filter((card): card is HTMLDivElement => card !== null);
      if (!root || !flow || cards.length === 0) return;

      const scrollEl = typeof scroller === "string" ? document.querySelector<HTMLElement>(scroller) : scroller;
      if (typeof scroller === "string" && !scrollEl) return;

      // Pictures start in the middle, tiny, and are placed by x / y / z / scale from here on
      gsap.set(cards, { xPercent: -50, yPercent: -50, x: 0, y: 0, z: 0, scale: 0, force3D: true });
      const place = cards.map((card) => ({
        x: gsap.quickSetter(card, "x", "px"),
        y: gsap.quickSetter(card, "y", "px"),
        z: gsap.quickSetter(card, "z", "px"),
        scaleX: gsap.quickSetter(card, "scaleX"),
        scaleY: gsap.quickSetter(card, "scaleY"),
      }));

      let width = flow.clientWidth;
      let height = flow.clientHeight;
      let progress = 0;

      // Draws every picture for a scroll position between 0 and 1
      const draw = () => {
        const { spread, mobileSpread, stagger, flightSpeed, perspective } = live.current;
        const reach = width < 800 ? mobileSpread : spread;
        const last = cards.length - 1;
        cards.forEach((card, index) => {
          // Each picture starts a little after the one before it, and flies for a fixed slice of the scroll.
          // Clamped to 0..1: a picture that has arrived stays arrived instead of flying on forever.
          const delay = last > 0 ? (index / last) * stagger : 0;
          const t = gsap.utils.clamp(0, 1, (progress - delay) * flightSpeed);
          const isBackdrop = index === last && last > 0;
          const target = scatterAt(index);

          let x = target.x * width * reach * t;
          let y = target.y * height * reach * t;
          let z = gsap.utils.interpolate(-perspective / 2, perspective, t);
          if (isBackdrop) {
            // The backdrop stays in the middle and only grows, at 40% of the speed
            x = 0;
            y = 0;
            z *= 0.4;
          }
          place[index]!.x(x);
          place[index]!.y(y);
          place[index]!.z(z);
          place[index]!.scaleX(t);
          place[index]!.scaleY(t);
          // A picture that has reached the camera is gone: hide it so it can't flash at the edges
          card.style.visibility = t <= 0 || (!isBackdrop && z >= perspective - 1) ? "hidden" : "visible";
        });
      };
      redraw.current = draw;

      const measure = () => {
        width = flow.clientWidth;
        height = flow.clientHeight;
      };

      const mm = gsap.matchMedia();

      // Reduced motion: no pin and no flying. The flow section is one still frame of the tunnel.
      mm.add("(prefers-reduced-motion: reduce)", () => {
        progress = 0.38;
        measure();
        draw();
        const onResize = () => {
          measure();
          draw();
        };
        window.addEventListener("resize", onResize);
        return () => window.removeEventListener("resize", onResize);
      });

      mm.add("(prefers-reduced-motion: no-preference)", () => {
        // Sections are one screen tall. For an inner scroller that is the scroller's height, which CSS can't know.
        const sizeSections = () => {
          if (scrollEl) root.style.setProperty("--images-flow-height", `${scrollEl.clientHeight}px`);
        };
        sizeSections();

        const trigger = ScrollTrigger.create({
          trigger: flow,
          scroller: scrollEl ?? undefined,
          start: "top top",
          end: () => `+=${Math.round(flow.clientHeight * scrollLength)}`,
          pin: true,
          pinSpacing: true,
          scrub: 1,
          // Measure again whenever ScrollTrigger refreshes (window resize, fonts, pictures), not on every resize event
          invalidateOnRefresh: true,
          onRefresh: (self) => {
            measure();
            progress = self.progress;
            draw();
          },
          onUpdate: (self) => {
            progress = self.progress;
            draw();
          },
        });

        // An inner scroller can change size without the window knowing. Wait for the resizing to settle, then measure once.
        let settle: gsap.core.Tween | undefined;
        const observer = scrollEl
          ? new ResizeObserver(() => {
              settle?.kill();
              settle = gsap.delayedCall(0.2, () => {
                sizeSections();
                ScrollTrigger.refresh();
              });
            })
          : null;
        if (scrollEl) observer?.observe(scrollEl);

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

      return () => {
        redraw.current = null;
        mm.revert();
      };
    },
    { scope: rootRef, dependencies: [items.length, scrollLength, scroller], revertOnUpdate: true },
  );

  const titleStyle: CSSProperties = {
    fontFamily: "var(--images-flow-title-font, Raleway, ui-sans-serif, system-ui, sans-serif)",
    fontSize: "clamp(2rem, 8vw, 6rem)",
    fontWeight: 200,
    letterSpacing: "0.3em",
    // The letter spacing also trails the last letter, so push the word back to the middle
    textIndent: "0.3em",
    textTransform: "uppercase",
    lineHeight: 1.1,
    marginBottom: "1rem",
    // A soft fade from the ink to a lighter ink across the word
    backgroundImage: `linear-gradient(135deg, ${inkColor} 0%, color-mix(in srgb, ${inkColor} 78%, ${pageColor}) 100%)`,
    WebkitBackgroundClip: "text",
    backgroundClip: "text",
    WebkitTextFillColor: "transparent",
  };
  const subtitleStyle: CSSProperties = {
    fontFamily: "var(--images-flow-title-font, Raleway, ui-sans-serif, system-ui, sans-serif)",
    fontSize: "clamp(0.75rem, 2vw, 1.2rem)",
    fontWeight: 300,
    letterSpacing: "0.15em",
    textIndent: "0.15em",
    opacity: 0.7,
  };
  const sectionStyle: CSSProperties = { height: "var(--images-flow-height, 100svh)" };

  return (
    <div ref={rootRef} className={`relative w-full overflow-x-clip ${className}`}>
      {/* Intro */}
      <section className="relative flex w-full flex-col items-center justify-center overflow-hidden px-6 text-center" style={{ ...sectionStyle, backgroundColor: pageColor, color: inkColor }}>
        <Heading style={titleStyle}>{introTitle}</Heading>
        {introSubtitle ? <p style={subtitleStyle}>{introSubtitle}</p> : null}
      </section>

      {/* Flow: this is the part that pins */}
      <section ref={flowRef} className="relative w-full overflow-hidden" style={{ ...sectionStyle, backgroundColor: stageColor }}>
        <p
          className="pointer-events-none absolute top-1/2 left-1/2 z-[100] w-full -translate-x-1/2 -translate-y-1/2 px-6 text-center whitespace-pre-line text-white opacity-80"
          style={{ fontFamily: "var(--images-flow-flow-font, 'Instrument Serif', Georgia, serif)", fontSize: "clamp(1.5rem, 5vw, 2rem)", letterSpacing: "0.05em" }}
        >
          {flowText}
        </p>
        <div className="absolute inset-0" style={{ perspective, transformStyle: "preserve-3d" }}>
          {items.map((item, index) => {
            const backdrop = index === lastIndex && lastIndex > 0;
            return (
              <div
                key={`${index}-${item.src}`}
                ref={(card) => {
                  cardRefs.current[index] = card;
                }}
                className={backdrop ? "absolute top-1/2 left-1/2 h-full w-full" : "absolute top-1/2 left-1/2 max-w-[90vw]"}
                // Before the script runs the pictures sit invisible in the middle, so nothing flashes on load
                style={{ ...(backdrop ? null : { width: cardWidth, height: cardHeight }), transform: "translate(-50%, -50%) scale(0)", visibility: "hidden", transformStyle: "preserve-3d", willChange: "transform" }}
              >
                <div className="relative h-full w-full overflow-hidden">
                  <img src={item.src} alt={item.alt} className="block h-full w-full object-cover" draggable={false} decoding="async" />
                  {backdrop ? <div aria-hidden="true" className="absolute inset-0 bg-black" style={{ opacity: dim }} /> : null}
                </div>
              </div>
            );
          })}
        </div>
      </section>

      {/* Outro */}
      <section className="relative flex w-full flex-col items-center justify-center overflow-hidden px-6 text-center" style={{ ...sectionStyle, backgroundColor: pageColor, color: inkColor }}>
        <Heading style={titleStyle}>{outroTitle}</Heading>
        {outroSubtitle ? <p style={subtitleStyle}>{outroSubtitle}</p> : null}
      </section>
    </div>
  );
}

The component. Installs to components/dimaac/images-flow.tsx.

Install

With the shadcn CLI

npx shadcn@latest add https://ui.dimaac.com/r/images-flow.json

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

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/images-flow.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 { ImagesFlow } from "@/components/dimaac/images-flow". Give its parent a size: it fills it.

Props

PropTypeDefaultDescription
images (required)(string | ImagesFlowImage)[]-The pictures. The last one is the full-screen backdrop, the others fly past. Twelve to thirty look best.
introTitle (required)string-The big word before the flow starts.
introSubtitlestring-A line under the intro title.
flowTextstring"Twenty-eight photos,\none scroll"The text that stays in the middle of the screen while the pictures fly. Use a line break for two lines.
outroTitle (required)string-The big word after the flow ends.
outroSubtitlestring-A line under the outro title.
spreadnumber0.7How far the pictures spread sideways on a wide screen. 0.7 puts the outermost ones at 70% of the screen away from the middle.
mobileSpreadnumber1.5The same, on a screen narrower than 800px, where the pictures need to travel further to leave the frame.
scrollLengthnumber10How long the flow takes, in screens of scrolling.
staggernumber0.81How much of the scroll the start times of the pictures are spread over, from 0 (all leave together) to 0.9.
flightSpeednumber4How fast a picture flies, as a multiple of the whole scroll. 4 means one picture needs a quarter of the scroll.
perspectivenumber2000Depth of the 3D scene in pixels. Pictures vanish as they pass this distance. Smaller is more dramatic.
cardWidthnumber500Width of each flying picture, in pixels. On a narrow screen it never goes wider than 90% of it.
cardHeightnumber350Height of each flying picture, in pixels.
dimnumber0.4How dark the full-screen backdrop is, from 0 (not at all) to 1 (black).
pageColorstring"#e9e9e9"Background of the intro and the outro.
inkColorstring"#1c1c1c"Colour of the intro and outro text.
stageColorstring"#1c1c1c"Background of the flow section, behind the pictures.
titleAs"h1" | "h2" | "h3"-The tag of the two big titles: use "h1" if this is the main heading of your page.
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 Images flow component (<ImagesFlow />) from DiMaac UI to this project.

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

Install it with:
npx shadcn@latest add https://ui.dimaac.com/r/images-flow.json

Then use it like this:
import { ImagesFlow } from "@/components/dimaac/images-flow";
<ImagesFlow
  images={images}
  introTitle={introTitle}
  outroTitle={outroTitle}
/>

If the shadcn CLI isn't set up here, fetch the registry JSON above, write files[0].content to components/dimaac/images-flow.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
images-flow.md
This page as Markdown: install, props and the full source
images-flow.json
The shadcn registry item

About

An intro title, a pinned tunnel and an outro title. While the tunnel is pinned, every scroll tick sends a stream of photos flying out of the middle of the screen toward the camera, each one starting a little after the one before and scattering to its own spot. The last photo is a dimmed full-screen backdrop that grows in behind the rest. The motion is scrubbed to the scrollbar, so it runs backwards when you scroll up, and a picture that has flown past the camera disappears cleanly. It measures once per refresh instead of rebuilding on every resize, works on the page or inside any scrolling element through the scroller prop, places extra pictures on a fixed spiral instead of at random, and shows one still frame of the tunnel when the visitor prefers reduced motion. Ported from the first DiMaac UI, with its hot-linked images replaced.

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

Desert Dunes and Mountain Range by Pablo Stanley on Lummi (Lummi License). Minimalist Urban Design by Ricardo Matos on Lummi (Lummi License). Portrait with Neon Sunglasses by Shaun Duval on Lummi (Lummi License). Futuristic Fashion Pose by Axel Photography on Lummi (Lummi License). Surreal 3D Planet Scene by Ricardo Matos on Lummi (Lummi License). Elegant Perfume Bottle by Dona Mara on Lummi (Lummi License). Serene Ocean Aerial View by Mikiwa on Lummi (Lummi License). Modern Interior with Red Wall by Siren Media on Lummi (Lummi License). Monochrome Portrait of a Young Woman by West Kast on Lummi (Lummi License). Fashion Portrait with Orange Visor by West Kast on Lummi (Lummi License). Lush Green Hills by SHIHO on Lummi (Lummi License). Minimalist Still Life by rena and Milan Bundalo on Lummi (Lummi License). Contemplative Urban Sunset by Atelier Aji on Lummi (Lummi License). Vibrant Cylindrical Arrangement by SHIHO on Lummi (Lummi License). Modern Architectural Design by rena on Lummi (Lummi License). Vivid Portrait on Pink by Amino on Lummi (Lummi License). Solitary Tree in Desert by alexaperios on Lummi (Lummi License). Futuristic Gold Profile by West Kast on Lummi (Lummi License). Elegant Vase with Dried Flowers by Pablo Stanley on Lummi (Lummi License). Serene Minimalist Scene with Palm Trees by Binks AI on Lummi (Lummi License). Serene Gradient Landscape by Nika on Lummi (Lummi License). Warm and Cool Portrait by Gerson Portillas on Lummi (Lummi License). Dramatic Coastline Aerial View by Cayetano Gros on Lummi (Lummi License). Professional Portrait by Benginur Hajjaj on Lummi (Lummi License). Contemplative Silhouette against Modern Minimalist Architecture by Viri Gutiérrez on Lummi (Lummi License). Avant-Garde Fashion Pose by Semihan Dosunmu on Lummi (Lummi License). Alpine Dawn Serenity by Viri Gutiérrez on Lummi (Lummi License).