DDBS UI
effect

Parallax Card

A wrapper that publishes the eased pointer position as CSS variables, so child layers can drift at different depths.

npx shadcn@latest add https://ui.develop-better-solutions.com/r/parallax-card.json
Fullscreen
Move your pointer
Depth 2
Parallax

Usage

parallax-card-example.tsx
import { ParallaxCard } from "@dbs/ui";

const drift = (k: number) => ({
  translate: `calc(var(--px, 0) * ${k}px) calc(var(--py, 0) * ${k * 0.7}px)`,
});

export default function ParallaxCardExample() {
  return (
    <ParallaxCard className="relative h-64 w-80 overflow-hidden rounded-2xl border border-line bg-surface p-6">
      <div
        className="absolute left-6 top-6 rounded-full border border-line bg-canvas px-3 py-1 text-xs text-ink-muted"
        style={drift(10)}
      >
        Move your pointer
      </div>
      <div
        className="absolute right-5 top-16 rounded-xl bg-gold px-3 py-2 text-sm font-medium text-dbs-black shadow-lg"
        style={drift(26)}
      >
        Depth 2
      </div>
      <div
        className="absolute bottom-6 left-6 text-3xl font-semibold tracking-[-0.03em] text-ink"
        style={drift(16)}
      >
        Parallax
      </div>
      <div
        className="absolute bottom-7 right-6 size-10 rounded-full bg-primary"
        style={drift(40)}
      />
    </ParallaxCard>
  );
}