← Components

Utilities

Image trail

Thumbnails that trail the pointer across a hero: every 80px of travel drops the next image, which scales in, then shrinks and fades.

Examples and variants

Hero

Move the pointer around the box.

Move the pointer around here

Example
function ImageTrailHero() {
  const images = [1, 2, 3, 4, 5, 6].map((n) => `/playground/tile-${n}.svg`)
  return (
    <ImageTrail images={images} className="flex h-56 w-full items-center justify-center rounded-(--shape-lg) bg-canvas shadow-1">
      <p className="pointer-events-none text-sm text-muted-foreground">Move the pointer around here</p>
    </ImageTrail>
  )
}

Spec drawing

Measured from the live component at default density. Each code maps to the token that sets it; change the token and the drawing follows.

Install

With the CLI

The shadcn CLI only delivers files: it copies our code from the Isotopi registry into your project and installs the packages it uses. Add the foundation once, then the component.

Terminal
npx shadcn@latest add https://isotopi.com/r/minimal.json
npx shadcn@latest add https://isotopi.com/r/image-trail.json

By hand

No CLI needed. Add the foundation once (see Getting started), then follow these steps. They include every component this one builds on.

  1. Install the packages it uses.

    Terminal
    npm install cn
  2. Copy this file to the same paths in your project. Imports use the @/ alias for your project root.

    • components/ui/image-trail.tsximage-trail
      components/ui/image-trail.tsx
      "use client"
      
      import * as React from "react"
      import { cn } from "cn"
      import { motionLevel } from "@/lib/overlay"
      
      /*
        Image trail: thumbnails that trail the pointer across a hero. Every
        `spacing` px of travel drops the next image; it scales in, then shrinks
        and fades. Still motion shows a static collage instead.
      */
      type Drop = { id: number; x: number; y: number; src: string; rotate: number }
      
      function ImageTrail({
        images,
        spacing = 80,
        alt = "",
        className,
        children,
      }: {
        images: string[]
        /** Pointer travel between drops, in px. */
        spacing?: number
        alt?: string
        className?: string
        children?: React.ReactNode
      }) {
        const ref = React.useRef<HTMLDivElement>(null)
        const last = React.useRef<{ x: number; y: number } | null>(null)
        const index = React.useRef(0)
        const [drops, setDrops] = React.useState<Drop[]>([])
        const [still, setStill] = React.useState(false)
      
        return (
          <div
            ref={ref}
            data-slot="image-trail"
            onPointerEnter={() => setStill(motionLevel(ref.current) === "still")}
            onPointerMove={(event) => {
              if (still || event.pointerType !== "mouse") return
              const box = event.currentTarget.getBoundingClientRect()
              const x = event.clientX - box.left
              const y = event.clientY - box.top
              const prev = last.current
              if (prev && Math.hypot(x - prev.x, y - prev.y) < spacing) return
              last.current = { x, y }
              const src = images[index.current % images.length]
              index.current += 1
              setDrops((all) => [...all.slice(-8), { id: Date.now() + index.current, x, y, src, rotate: (index.current % 5) * 4 - 8 }])
            }}
            onPointerLeave={() => {
              last.current = null
            }}
            className={cn("image-trail relative overflow-hidden", className)}
          >
            {still
              ? images.slice(0, 4).map((src, i) => (
                  // Plain <img>: kit components work in any React app, not only Next.js.
                  // eslint-disable-next-line @next/next/no-img-element
                  <img key={src} src={src} alt="" aria-hidden className="image-trail-static absolute size-(--trail-size) rounded-(--trail-corner) object-cover shadow-(--trail-elevation)" style={{ left: `${15 + i * 20}%`, top: `${20 + (i % 2) * 30}%` }} />
                ))
              : drops.map((drop) => (
                  // eslint-disable-next-line @next/next/no-img-element
                  <img
                    key={drop.id}
                    src={drop.src}
                    alt={alt}
                    aria-hidden
                    onAnimationEnd={() => setDrops((all) => all.filter((d) => d.id !== drop.id))}
                    className="image-trail-drop pointer-events-none absolute size-(--trail-size) rounded-(--trail-corner) object-cover shadow-(--trail-elevation)"
                    style={{ left: drop.x, top: drop.y, "--rotate": `${drop.rotate}deg` } as React.CSSProperties}
                  />
                ))}
            <div className="relative">{children}</div>
          </div>
        )
      }
      
      export { ImageTrail }
      

Imports

What the examples on this page import:

Imports
import { ArrowRightIcon } from "lucide-react"
import { Avatar, AvatarFallback } from "@/components/ui/avatar"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Fab } from "@/components/ui/fab"
import { ImageTrail } from "@/components/ui/image-trail"
import { Magnetic } from "@/components/ui/magnetic"
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"
import { Heading } from "@/components/ui/typography"
import { PlusIcon } from "lucide-react"

Anatomy

  1. 1Area · Any container; children sit above the trail.
  2. 2Drops · --trail-size, --trail-corner, --trail-elevation.

Props

PropTypeDefaultDescription
imagesstring[]—Image URLs, used in turn.
spacingnumber80Pointer travel between drops, in px.
childrenReactNode—Content above the trail.

Tokens

Every visual spec is a component token in styles/tokens/components.css, pointing at a semantic token. Change a token to restyle the component; themes change the semantic layer.

TokenPoints toLightDark
--trail-sizevar(--space-24)96pxsame
--trail-cornervar(--shape-md)14pxsame
--trail-elevationvar(--elevation-3)0 1px 1px -0.5px oklch(0.22 0.01 260 / 8%), 0 3px 3px -1.5px oklch(0.22 0.01 260 / 8%), 0 6px 6px -3px oklch(0.22 0.01 260 / 8%), 0 12px 12px -6px oklch(0.22 0.01 260 / 8%), 0 24px 24px -12px oklch(0.22 0.01 260 / 8%), 0 48px 48px -24px oklch(0.22 0.01 260 / 6%)0 8px 20px oklch(0 0 0 / 45%), 0 20px 44px oklch(0 0 0 / 40%)

Motion

TriggerWhat happensTokens
Pointer moveEach image scales in, holds, then shrinks and fades.--duration-settle

Calm keeps the motion without overshoot. Still (and reduced motion) keeps a designed frame with no movement.

Accessibility

  • Decorative (aria-hidden). Still motion shows a static collage; reduced motion shows nothing.

Usage

Do

  • Use on a marketing hero.

Don’t

  • Don't use in product UI.

Code

components/ui/image-trail.tsx
"use client"

import * as React from "react"
import { cn } from "cn"
import { motionLevel } from "@/lib/overlay"

/*
  Image trail: thumbnails that trail the pointer across a hero. Every
  `spacing` px of travel drops the next image; it scales in, then shrinks
  and fades. Still motion shows a static collage instead.
*/
type Drop = { id: number; x: number; y: number; src: string; rotate: number }

function ImageTrail({
  images,
  spacing = 80,
  alt = "",
  className,
  children,
}: {
  images: string[]
  /** Pointer travel between drops, in px. */
  spacing?: number
  alt?: string
  className?: string
  children?: React.ReactNode
}) {
  const ref = React.useRef<HTMLDivElement>(null)
  const last = React.useRef<{ x: number; y: number } | null>(null)
  const index = React.useRef(0)
  const [drops, setDrops] = React.useState<Drop[]>([])
  const [still, setStill] = React.useState(false)

  return (
    <div
      ref={ref}
      data-slot="image-trail"
      onPointerEnter={() => setStill(motionLevel(ref.current) === "still")}
      onPointerMove={(event) => {
        if (still || event.pointerType !== "mouse") return
        const box = event.currentTarget.getBoundingClientRect()
        const x = event.clientX - box.left
        const y = event.clientY - box.top
        const prev = last.current
        if (prev && Math.hypot(x - prev.x, y - prev.y) < spacing) return
        last.current = { x, y }
        const src = images[index.current % images.length]
        index.current += 1
        setDrops((all) => [...all.slice(-8), { id: Date.now() + index.current, x, y, src, rotate: (index.current % 5) * 4 - 8 }])
      }}
      onPointerLeave={() => {
        last.current = null
      }}
      className={cn("image-trail relative overflow-hidden", className)}
    >
      {still
        ? images.slice(0, 4).map((src, i) => (
            // Plain <img>: kit components work in any React app, not only Next.js.
            // eslint-disable-next-line @next/next/no-img-element
            <img key={src} src={src} alt="" aria-hidden className="image-trail-static absolute size-(--trail-size) rounded-(--trail-corner) object-cover shadow-(--trail-elevation)" style={{ left: `${15 + i * 20}%`, top: `${20 + (i % 2) * 30}%` }} />
          ))
        : drops.map((drop) => (
            // eslint-disable-next-line @next/next/no-img-element
            <img
              key={drop.id}
              src={drop.src}
              alt={alt}
              aria-hidden
              onAnimationEnd={() => setDrops((all) => all.filter((d) => d.id !== drop.id))}
              className="image-trail-drop pointer-events-none absolute size-(--trail-size) rounded-(--trail-corner) object-cover shadow-(--trail-elevation)"
              style={{ left: drop.x, top: drop.y, "--rotate": `${drop.rotate}deg` } as React.CSSProperties}
            />
          ))}
      <div className="relative">{children}</div>
    </div>
  )
}

export { ImageTrail }