# Poster Intro
*URL: https://www.grettech.com/components/poster-intro*

A film-style poster that builds itself: layered art flies back from the camera by depth, the frame dollies out and the title wipes in with a spring.

- Depth-based dolly: nearer layers start further into the camera
- Waits for the art behind a loading bar, then plays when on screen
- Real-text title with a spring wipe, a focus pull and a gloss sweep
- Pointer parallax after the intro; Motion-driven, reduced-motion aware

## Install with the shadcn CLI
```bash
npx shadcn@latest add https://www.grettech.com/api/registry/poster-intro
```
With its demo: `npx shadcn@latest add https://www.grettech.com/api/registry/poster-intro-demo`

**Dependencies:** npm: motion, clsx, tailwind-merge

## Manual installation
**Step 1: Install dependencies**
Install the packages this component uses. It also needs the `cn` helper in `lib/utils.ts`, which `npx shadcn@latest init` adds.

```bash
npm install motion clsx tailwind-merge
```

**Step 2: Copy the source code**
Add these files to your project components directory.

File: `components/ui/poster-intro.tsx`
```tsx
"use client"

import { cn } from "@/lib/utils"
import {
  animate,
  type AnimationPlaybackControls,
  type DOMKeyframesDefinition,
  type ValueAnimationTransition,
} from "motion/react"
import * as React from "react"

export type PosterLayer = {
  /** A transparent image, drawn to fill the poster (object-fit: cover) */
  src: string
  alt?: string
  /** 0 is the far background, 1 the nearest layer. Nearer layers start
   * further into the camera and drift more with the pointer */
  depth: number
  /** Seconds before it fades in; by default the layers arrive back to front */
  delay?: number
}

export interface PosterIntroProps extends Omit<
  React.HTMLAttributes<HTMLElement>,
  "title"
> {
  /** The artwork, back to front */
  layers: PosterLayer[]
  /** Set as real text over the art; wipes in and sharpens last */
  title?: string
  /** Small line above the title */
  kicker?: string
  /** Line under the title, e.g. a date */
  tagline?: string
  /** Billing-block small print along the bottom of the poster */
  credits?: string
  /** Length of the intro, in seconds */
  duration?: number
  /** How far the camera starts pushed in: 1 means no push */
  camera?: number
  /** Depth of the dolly: 0 flattens the layers, 1 is the full effect */
  depth?: number
  aspectRatio?: "1 / 1" | "4 / 5" | "3 / 4" | "16 / 9"
  /** Layers drift with the pointer once the intro has played */
  parallax?: boolean
  /** Show a loading bar while the layers download */
  loader?: boolean
  /** Film grain over the art */
  grain?: boolean
  /** Glow behind the poster and the colour of its shadow */
  glowColor?: string
  /** Three colours for the title's gradient fill */
  titleColors?: [string, string, string]
}

const REDUCED = "(prefers-reduced-motion: reduce)"
/** The length the layer timings below were tuned for */
const BASE = 3.6

const GRAIN = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`

const ratioOf = (aspect: string) => {
  const [w, h] = aspect.split("/").map(Number)
  return w > 0 && h > 0 ? w / h : 1
}

/**
 * A poster that builds itself like a film title card: transparent art
 * layers fly back from the camera at speeds set by their depth and fade in
 * back to front, the whole frame dollies out, and the title wipes in and
 * snaps into focus. It waits for the art (with a loading bar) and for the
 * poster to be on screen, then the layers follow the pointer. Transforms
 * and opacity only, animated with Motion; reduced motion shows the
 * finished poster.
 */
export const PosterIntro = React.forwardRef<HTMLElement, PosterIntroProps>(
  (
    {
      layers,
      title,
      kicker,
      tagline,
      credits,
      duration = BASE,
      camera = 1.14,
      depth = 1,
      aspectRatio = "4 / 5",
      parallax = true,
      loader = true,
      grain = true,
      glowColor = "#c026d3",
      titleColors = ["#ffe8a3", "#ff6fa5", "#8b5cf6"],
      className,
      style,
      ...props
    },
    ref
  ) => {
    const poster = React.useRef<HTMLDivElement>(null)
    const running = React.useRef<AnimationPlaybackControls[]>([])
    const [loaded, setLoaded] = React.useState(0)
    const [ready, setReady] = React.useState(false)
    const [inView, setInView] = React.useState(false)
    const [phase, setPhase] = React.useState<"waiting" | "playing" | "done">(
      "waiting"
    )
    const srcs = layers.map((l) => l.src).join("|")

    // Wait for every layer to download and decode, so the build never plays
    // with holes in it. A broken or slow image doesn't hold it up forever.
    React.useEffect(() => {
      const box = poster.current
      if (!box) return
      let live = true
      setReady(false)
      setLoaded(0)
      const images = [
        ...box.querySelectorAll<HTMLImageElement>("img[data-layer]"),
      ]
      const each = images.map((img) =>
        img
          .decode()
          .catch(() => {})
          .then(() => live && setLoaded((n) => n + 1))
      )
      const timeout = new Promise((r) => setTimeout(r, 8000))
      Promise.race([Promise.all(each), timeout]).then(
        () => live && setReady(true)
      )
      return () => {
        live = false
      }
    }, [srcs])

    React.useEffect(() => {
      const box = poster.current
      if (!box) return
      const seen = new IntersectionObserver(
        ([entry]) => entry?.isIntersecting && setInView(true),
        { threshold: 0.35 }
      )
      seen.observe(box)
      return () => seen.disconnect()
    }, [])

    const play = React.useCallback(() => {
      const box = poster.current
      if (!box) return
      for (const a of running.current) a.stop()
      running.current = []
      box.style.setProperty("--px", "0")
      box.style.setProperty("--py", "0")
      // Reduced motion runs the same sequence in no time: the finished
      // poster, with nothing moving
      const still = window.matchMedia(REDUCED).matches
      setPhase(still ? "done" : "playing")
      const k = still ? 0 : duration / BASE
      const q = (s: string) => box.querySelector<HTMLElement>(s)

      /**
       * Animates an element with Motion from one pose to another. Opacity
       * is set straight away, so anything waiting on a delay stays hidden
       */
      const run = (
        el: HTMLElement | null,
        from: Record<string, number | string>,
        to: Record<string, number | string | (number | string)[]>,
        options: ValueAnimationTransition
      ) => {
        if (!el) return null
        if (from.opacity !== undefined) el.style.opacity = String(from.opacity)
        const frames = Object.fromEntries(
          Object.entries(to).map(([key, value]) => [
            key,
            Array.isArray(value) || from[key] === undefined
              ? value
              : [from[key], value],
          ])
        ) as DOMKeyframesDefinition
        const a = animate(el, frames, still ? { duration: 0 } : options)
        running.current.push(a)
        return a
      }

      // The frame dollies out from the camera
      run(
        q("[data-camera]"),
        { scale: camera },
        { scale: 1 },
        {
          duration,
          ease: [0.33, 0, 0.2, 1],
        }
      )
      // Each layer flies back from as far as its depth puts it, and fades
      // in back to front
      let last = 0
      box.querySelectorAll<HTMLElement>("img[data-layer]").forEach((img, i) => {
        const near = Math.max(0, Number(img.dataset.depth) || 0)
        const own = img.dataset.delay ? Number(img.dataset.delay) : NaN
        const start = 1 + near * 1.45 * depth
        const delay = (Number.isFinite(own) ? own : 0.4 + i * 0.1) * k
        last = Math.max(last, delay)
        run(
          img,
          { scale: start },
          { scale: 1 },
          {
            duration,
            ease: [0.16, 1, 0.3, 1],
          }
        )
        run(
          img,
          { opacity: 0 },
          { opacity: 1 },
          {
            duration: 0.7 * k,
            delay,
            ease: "easeOut",
          }
        )
      })
      // The title wipes down with a spring and comes into focus
      const at = last + 0.35 * k
      run(
        q("[data-kicker]"),
        { opacity: 0, y: 10 },
        { opacity: 1, y: 0 },
        {
          duration: 0.6 * k,
          delay: Math.max(0, at - 0.25 * k),
          ease: "easeOut",
        }
      )
      const title = q("[data-title]")
      if (title) {
        title.style.clipPath = "inset(0 0 100% 0)"
        const wipe = animate(100, 0, {
          ...(still
            ? { duration: 0 }
            : {
                type: "spring",
                bounce: 0.45,
                visualDuration: 1.1 * k,
                delay: at,
              }),
          onUpdate: (v) => (title.style.clipPath = `inset(0 0 ${v}% 0)`),
        })
        running.current.push(wipe)
      }
      run(
        title,
        { filter: "blur(10px)", scale: 1.08 },
        { filter: "blur(0px)", scale: 1 },
        { duration: 1.1 * k, delay: at, ease: [0.16, 1, 0.3, 1] }
      )
      run(
        q("[data-tagline]"),
        { opacity: 0, y: -6 },
        { opacity: 1, y: 0 },
        {
          duration: 0.7 * k,
          delay: at + 0.6 * k,
          ease: "easeOut",
        }
      )
      run(
        q("[data-credits]"),
        { opacity: 0 },
        { opacity: 1 },
        {
          duration: 0.9 * k,
          delay: at + 0.7 * k,
          ease: "easeOut",
        }
      )
      // A gloss of light crosses the poster as it settles
      const glossAt = Math.max(duration, at + 0.9 * k) - 0.6 * k
      const gloss = q("[data-gloss]")
      run(
        gloss,
        { x: "-100%" },
        { x: "100%" },
        {
          duration: 1.3 * k,
          delay: glossAt,
          ease: [0.45, 0, 0.2, 1],
        }
      )
      const end = run(
        gloss,
        { opacity: 0 },
        { opacity: [0, 1, 1, 0] },
        {
          duration: 1.3 * k,
          delay: glossAt,
          times: [0, 0.3, 0.7, 1],
        }
      )
      if (!still)
        (end ?? running.current.at(-1))?.finished.then(() => setPhase("done"))
    }, [camera, depth, duration])

    // Play once the art is in and the poster is on screen; again whenever
    // the timing or the art changes
    const art = layers
      .map((l) => `${l.src}@${l.depth}@${l.delay ?? ""}`)
      .join("|")
    React.useEffect(() => {
      if (ready && inView) play()
    }, [ready, inView, play, art])

    React.useEffect(
      () => () => {
        for (const a of running.current) a.stop()
      },
      []
    )

    const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
      if (!parallax || phase !== "done" || e.pointerType === "touch") return
      const box = e.currentTarget.getBoundingClientRect()
      const x = ((e.clientX - box.left) / box.width - 0.5) * 2
      const y = ((e.clientY - box.top) / box.height - 0.5) * 2
      e.currentTarget.style.setProperty("--px", x.toFixed(3))
      e.currentTarget.style.setProperty("--py", y.toFixed(3))
    }
    const onPointerLeave = (e: React.PointerEvent<HTMLDivElement>) => {
      e.currentTarget.style.setProperty("--px", "0")
      e.currentTarget.style.setProperty("--py", "0")
    }

    const ratio = ratioOf(aspectRatio)
    const total = layers.length
    const progress = total ? Math.round((loaded / total) * 100) : 100
    // Before it plays, the poster waits in its starting pose (hidden), so
    // nothing flashes in its final state first
    const hidden = phase === "waiting"

    return (
      <section
        ref={ref}
        className={cn(
          "relative isolate w-full overflow-hidden bg-[#07050d] px-4 py-10 sm:py-14",
          className
        )}
        style={{
          backgroundImage: `radial-gradient(60% 55% at 50% 42%, color-mix(in oklab, ${glowColor} 32%, transparent), transparent 72%)`,
          ...style,
        }}
        {...props}
      >
        <div
          ref={poster}
          onPointerMove={onPointerMove}
          onPointerLeave={onPointerLeave}
          className="[container-type:inline-size] relative mx-auto w-full overflow-hidden rounded-[18px] bg-[#0b0718]"
          style={{
            aspectRatio,
            maxWidth: `min(100%, calc(82svh * ${ratio}))`,
            boxShadow: `0 50px 120px -40px color-mix(in oklab, ${glowColor} 70%, transparent), 0 0 0 1px rgb(255 255 255 / 0.08)`,
          }}
        >
          <div
            data-camera=""
            className="absolute inset-0"
            style={{ opacity: hidden ? 0 : 1 }}
          >
            {layers.map((layer, i) => (
              // The wrapper drifts with the pointer; the image itself
              // carries the intro, so the two never fight
              <div
                key={`${layer.src}-${i}`}
                className="absolute inset-0"
                style={{
                  translate: `calc(var(--px, 0) * ${(layer.depth * -14).toFixed(1)}px) calc(var(--py, 0) * ${(layer.depth * -9).toFixed(1)}px)`,
                  transition: "translate 900ms cubic-bezier(0.2, 0.8, 0.2, 1)",
                }}
              >
                {/* eslint-disable-next-line @next/next/no-img-element */}
                <img
                  data-layer=""
                  data-depth={layer.depth}
                  data-delay={layer.delay}
                  src={layer.src}
                  alt={layer.alt ?? ""}
                  draggable={false}
                  className="pointer-events-none absolute inset-0 size-full object-cover select-none"
                />
              </div>
            ))}

            {(kicker || title || tagline) && (
              <div className="absolute inset-x-0 top-[7%] flex flex-col items-center px-[6cqw] text-center">
                {kicker && (
                  <p
                    data-kicker=""
                    className="mb-[1.5cqw] text-[clamp(8px,2.2cqw,14px)] font-semibold tracking-[0.42em] text-white/75 uppercase"
                  >
                    {kicker}
                  </p>
                )}
                {title && (
                  <h2
                    data-title=""
                    className="text-[clamp(2rem,15cqw,9rem)] leading-[0.86] font-black tracking-[-0.045em] uppercase italic"
                  >
                    <span
                      className="block bg-clip-text px-[0.08em] text-transparent [filter:drop-shadow(0_0.06em_0.12em_rgb(0_0_0/0.45))]"
                      style={{
                        backgroundImage: `linear-gradient(180deg, ${titleColors[0]} 10%, ${titleColors[1]} 55%, ${titleColors[2]} 95%)`,
                      }}
                    >
                      {title}
                    </span>
                  </h2>
                )}
                {tagline && (
                  <p
                    data-tagline=""
                    className="mt-[2cqw] rounded-full bg-black/25 px-[2.4cqw] py-[0.8cqw] text-[clamp(8px,2.3cqw,15px)] font-medium tracking-[0.3em] text-white/90 uppercase ring-1 ring-white/20 backdrop-blur-sm"
                  >
                    {tagline}
                  </p>
                )}
              </div>
            )}

            {credits && (
              <p
                data-credits=""
                className="absolute inset-x-[9%] bottom-[3.5%] text-center text-[clamp(6px,1.55cqw,10px)] leading-[1.35] font-medium tracking-[0.16em] text-balance text-white/55 uppercase [font-stretch:condensed]"
              >
                {credits}
              </p>
            )}
          </div>

          {/* Print finish: grain, a vignette, an inner border and the gloss */}
          <div
            aria-hidden="true"
            className="pointer-events-none absolute inset-0"
          >
            {grain && (
              <div
                className="absolute inset-0 opacity-25 mix-blend-overlay"
                style={{ backgroundImage: GRAIN }}
              />
            )}
            <div className="absolute inset-0 bg-[radial-gradient(ellipse_at_center,transparent_55%,rgb(0_0_0/0.45))]" />
            <div className="absolute inset-[2.2cqw] rounded-[10px] ring-1 ring-white/15" />
            <div
              data-gloss=""
              className="absolute inset-y-0 -left-1/4 w-[150%] opacity-0 mix-blend-soft-light"
              style={{
                backgroundImage:
                  "linear-gradient(105deg, transparent 35%, rgb(255 255 255 / 0.55) 48%, rgb(255 255 255 / 0.85) 50%, rgb(255 255 255 / 0.55) 52%, transparent 65%)",
              }}
            />
          </div>

          {loader && (
            <div
              aria-hidden={ready}
              className={cn(
                "pointer-events-none absolute inset-x-[10%] bottom-[9%] flex flex-col gap-2 transition-opacity duration-500",
                ready ? "opacity-0" : "opacity-100"
              )}
            >
              <div className="flex items-baseline justify-between text-[11px] font-medium tracking-[0.3em] text-white/70 uppercase">
                <span role="status">{ready ? "Ready" : "Loading"}</span>
                <span className="font-mono tracking-normal tabular-nums">
                  {progress}%
                </span>
              </div>
              <div className="h-[3px] overflow-hidden rounded-full bg-white/10">
                <div
                  className="h-full w-full origin-left rounded-full bg-white/80 transition-transform duration-300"
                  style={{ scale: `${progress / 100} 1` }}
                />
              </div>
            </div>
          )}
        </div>
      </section>
    )
  }
)
PosterIntro.displayName = "PosterIntro"

```

**Step 3: Framework Adjustments (Optional)**
If you are manually copying this code into a Vite or Remix project (without using the CLI), make sure to remove the `"use client";` directive from the very top of the file.

## Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| `layers` | `PosterLayer[]` | - | Yes | The artwork as transparent images, back to front. Each fills the poster. |
| `layers.src` | `string` | - | Yes | Image URL; a transparent PNG, WebP or SVG. |
| `layers.alt` | `string` | - | No | Describe the scene on one layer; leave the rest empty. |
| `layers.depth` | `number` | - | Yes | 0 is the far background, 1 the nearest layer. Nearer layers start further into the camera and drift more with the pointer. |
| `layers.delay` | `number` | - | No | Seconds before the layer fades in; by default the layers arrive back to front. |
| `title` | `string` | - | No | Set as real text over the art; wipes in and sharpens last. |
| `kicker` | `string` | - | No | Small line above the title. |
| `tagline` | `string` | - | No | Line under the title, such as a date. |
| `credits` | `string` | - | No | Billing-block small print along the bottom of the poster. |
| `duration` | `number` | `3.6` | No | Length of the intro, in seconds. |
| `camera` | `number` | `1.14` | No | How far the camera starts pushed in; 1 means no push. |
| `depth` | `number` | `1` | No | Depth of the dolly: 0 flattens the layers, 1 is the full effect. |
| `aspectRatio` | `"1 / 1" \| "4 / 5" \| "3 / 4" \| "16 / 9"` | `"4 / 5"` | No | Shape of the poster. |
| `parallax` | `boolean` | `true` | No | Layers drift with the pointer once the intro has played. |
| `loader` | `boolean` | `true` | No | Show a loading bar while the layers download. |
| `grain` | `boolean` | `true` | No | Film grain over the art. |
| `glowColor` | `string` | `"#c026d3"` | No | Glow behind the poster and the colour of its shadow. |
| `titleColors` | `[string, string, string]` | `["#ffe8a3", "#ff6fa5", "#8b5cf6"]` | No | Three colours for the title's gradient, top to bottom. |
| `className` | `string` | - | No | Extra classes for the section. |

## Usage
```tsx
"use client"

import { PosterIntro, type PosterLayer } from "@/components/ui/poster-intro"

// Original art in seven transparent layers, back to front
const LAYERS: PosterLayer[] = [
  { src: "https://www.grettech.com/gridtic/poster/sky.svg", depth: 0.05 },
  { src: "https://www.grettech.com/gridtic/poster/sun.svg", depth: 0.15 },
  { src: "https://www.grettech.com/gridtic/poster/skyline.svg", depth: 0.3 },
  { src: "https://www.grettech.com/gridtic/poster/sea.svg", depth: 0.45 },
  { src: "https://www.grettech.com/gridtic/poster/palms.svg", depth: 0.7 },
  { src: "https://www.grettech.com/gridtic/poster/heli.svg", depth: 0.85 },
  {
    src: "https://www.grettech.com/gridtic/poster/road.svg",
    alt: "A coast road at dusk, with palms, a city skyline and a helicopter over the sea",
    depth: 1,
  },
]

export default function PosterIntroDemo() {
  return (
    <PosterIntro
      layers={LAYERS}
      kicker="A Gridtic original"
      title="Neon Coast"
      tagline="Arriving 2027"
      credits="Gridtic Studios presents · A layered poster intro · Seven layers of original art · Built with React and Motion"
      className="rounded-3xl"
    />
  )
}

```
