FreeMIT LicenseFeatured

Perspective Cards — 3D Parallax Image Gallery Hero for React & Framer Motion

A 3D parallax image gallery hero for React: cards float around your headline, follow the cursor like a camera, lift and face you on hover, and open into a cinematic lightbox. Framer Motion, light/dark themes, keyboard, touch and reduced-motion support.

by UpFork, built by Ramin ValadanComponentUpdated 26 Oct 2026

Read how it was madeBehind the build5 lessons
Watch0
Preview of Perspective Cards — 3D Parallax Image Gallery Hero for React & Framer Motion

Code

20 files · 1 package · 20 assets

"use client";

import { useEffect, type RefObject } from "react";

const FOCUSABLE = 'a[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';

function focusables(root: HTMLElement) {
  return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(
    (el) => !el.closest("[inert],[hidden]") && (typeof el.checkVisibility !== "function" || el.checkVisibility()),
  );
}

/**
 * Keeps Tab and Shift+Tab inside `ref` while `active`, and moves focus in (to `initial`, or the container) when it
 * turns on. Restoring focus afterwards is the caller's call: it knows which element should get it back.
 */
export function useFocusTrap(ref: RefObject<HTMLElement | null>, active: boolean, initial?: RefObject<HTMLElement | null>) {
  useEffect(() => {
    const root = ref.current;
    if (!active || !root) return;
    (initial?.current ?? root).focus({ preventScroll: true });
    const onKey = (e: KeyboardEvent) => {
      if (e.key !== "Tab") return;
      const list = focusables(root);
      if (!list.length) {
        e.preventDefault();
        root.focus({ preventScroll: true });
        return;
      }
      const first = list[0];
      const last = list[list.length - 1];
      const now = document.activeElement;
      if (e.shiftKey && (now === first || !root.contains(now))) {
        e.preventDefault();
        last.focus();
      } else if (!e.shiftKey && (now === last || !root.contains(now))) {
        e.preventDefault();
        first.focus();
      }
    };
    document.addEventListener("keydown", onKey, true);
    return () => document.removeEventListener("keydown", onKey, true);
  }, [ref, active, initial]);
}
20 files20 assets1 package

From the workbench

Written about Perspective Cards — 3D Parallax Image Gallery Hero for React & Framer Motion

By the developer who built it: how it works, with its real code and live preview in the text, and the lessons learned along the way.

About

Perspective Cards turns a collection into a scene. Your image cards float in 3D around the headline, each one turned toward it, and the whole scene moves with the cursor like a camera: near cards travel more than far ones while the headline drifts gently the other way. Click a card and that exact card grows into a cinematic lightbox, then flies back into its place when you close it.

What it does

  • Cards that feel physical. On hover a card lifts toward you and turns to face you, a highlight follows the pointer across it, its shadow deepens and its caption reveals a one-line description. Idle cards breathe gently; the two farthest sit softly out of focus.
  • An entrance that deals the cards. On first view the cards are dealt outward from the headline, nearest first, and land with a spring.
  • A cinematic lightbox. Arrow keys, Home and End, swipe to browse and swipe down to close, thumbnails, a counter, neighbours preloaded and page scroll locked without a jump.
  • Three layouts. Orbit (the default), scatter and arc, each deterministic for a seed, with captions kept clear of other cards.
  • Every screen size. A two-row arc under the headline on tablets; a fanned deck over a snap-scrolling strip on phones, with tilt-to-move after a tap on "Enable motion".
  • Light, dark or auto. Auto follows your site's .dark class or the system setting. Any accent colour; six CSS variables to re-theme.
  • Accessible. Real buttons in reading order, keyboard focus that lifts a card like hover, a proper modal dialog with a focus trap and screen-reader announcements, and full reduced-motion support.

Fast by design

Pointer movement, idle float, hover and scroll all run on motion values, so React never re-renders while anything moves, and only transform and opacity change. The main bundle is under 12 kB gzipped; the lightbox and the phone layout load as small separate chunks. Our demo scores 98+ for performance and 100 for accessibility, best practices and SEO in Lighthouse (desktop), with zero layout shift.

What's included

  • The PerspectiveCards component in TypeScript, with its own stylesheet
  • Reusable pieces: PerspectiveLightbox, PerspectiveCard, usePointerParallax and the pure layout functions
  • Three demos: orbit (follows your theme), scatter (dark with a warm accent) and arc
  • Ten demo photos from Unsplash, ready to swap for your own

Stack and requirements

  • React 18 or 19, TypeScript
  • motion (Framer Motion) is the only dependency
  • Works in the Next.js App Router and in Vite; Tailwind CSS is optional because the styles ship with the component
  • Use next/image through the renderImage prop

Make it yours

Pass your own items (image, title, alt text, size, and an optional description and link), headline, call to action and accent colour. Tune depth, parallax and tilt, or try another composition with seed.

Reviews and bugs

0 reviews · 0 bugs

Ship it0With fixes0Skip0· 0 reviews

0 bugs0 open0 fixed

Members who have it review it and report its bugs. Sign in

No reviews or bugs yet.

Manual installation

Without the CLI

  1. 01

    Install the packages

    npm install motion
  2. 02

    Copy the files into your project

    • components/perspective-cards/hooks/useFocusTrap.ts
    • components/perspective-cards/hooks/useIdleFloat.ts
    • components/perspective-cards/hooks/usePointerParallax.ts
    • components/perspective-cards/hooks/useReducedMotion.ts
    • components/perspective-cards/hooks/useScrollLock.ts
    • components/perspective-cards/index.ts
    • components/perspective-cards/layout/arc.ts
    • components/perspective-cards/layout/index.ts
    • components/perspective-cards/layout/orbit.ts
    • components/perspective-cards/layout/prng.ts
    • components/perspective-cards/layout/scatter.ts
    • components/perspective-cards/layout/separate.ts
    • components/perspective-cards/layout/shared.ts
    • components/perspective-cards/PerspectiveCard.tsx
    • components/perspective-cards/PerspectiveCards.tsx
    • components/perspective-cards/PerspectiveDeck.tsx
    • components/perspective-cards/PerspectiveLightbox.tsx
    • components/perspective-cards/rig.ts
    • components/perspective-cards/styles.css
    • components/perspective-cards/types.ts

    The paths follow the shadcn/ui layout, with @/ as your project’s import alias.

  3. 03

    Its pictures load from UpFork

    The code above points at UpFork’s copies (2.1 MB), so there’s nothing to copy. To host them yourself, use Download source: its ZIP has the files where the code expects them, and a README on the switch.

Before you buy

Everything you need to know

How this component gets from the preview into your project, and what buyers ask most.

How to use it

From the preview to your project

  1. 01

    Try it in the preview

    Switch between light and dark, and resize it to phone and tablet widths, before you decide.

  2. 02

    Get it

    Free products are yours with a free account. Paid ones settle in USDT on TRON, sent straight to the wallet on your order.

  3. 03

    Install it

    Components go into your project with one shadcn command, dependencies included. Everything else downloads with a checksum.

  4. 04

    Make it yours

    It's your code now: rename it, restyle it and wire in your real data.

  5. 05

    Or hand it to your AI

    Copy the prompt and let your coding assistant place it in your project, following your conventions.

Building with an AI assistant?

Copy a ready-made prompt with the code, its dependencies and a demo, and your assistant can put it in place for you.

Copy AI prompt

Selling your own work?

Get approved once, then publish components, templates and mobile components, paid in USDT straight to your own wallet.