Components / Motion
Tilt Card
A card that leans toward the pointer, with an optional holographic sheen that follows it.
Hover me
The card leans toward the pointer and the foil follows it.
Installation
npx shadcn@latest add https://jiaweing.com/r/tilt-card.jsonWith the @jiaweing namespace set up, use @jiaweing/tilt-card in place of the URL.
Usage
tsx
import { TiltCard } from "@/components/tilt-card";tsx
<TiltCard className="rounded-2xl" foil>
<img alt="" className="rounded-2xl" src="/card.png" />
</TiltCard>- It sets --mx and --my (0 to 1) on itself, so children can follow the pointer too, for example a background position.
- Touch input and reduced motion keep the card flat.
Props
TiltCard
| Prop | Type | Default | Description |
|---|---|---|---|
| max | number | 9 | The furthest it leans, in degrees. |
| foil | boolean | false | Adds a holographic sheen that follows the pointer. |
| perspective | number | 900 | Perspective in pixels. Smaller looks steeper. |
| className | string | - | Extra classes, merged with cn. |
MIT licensed. Copy it, change it, ship it.