Overview
Components
Text Animations
A cursor-reactive card wrapper with configurable tilt depth, hover scale, perspective, and optional spotlight.
John Doe
5367 4567 8901 2345
Exp.
12/25
preview.svelte
<script lang="ts"> import { TiltCard } from "$lib/components/spell/tilt-card/index.js";</script>
{#snippet spellLogo()} <svg aria-hidden="true" width="24" height="24" viewBox="0 0 262 278" fill="none" xmlns="http://www.w3.org/2000/svg" class="size-6 text-neutral-950 dark:text-white" > <path d="M57.6541 65.6418C58.8281 64.8226 60.4465 65.2097 61.2647 66.3823C64.3285 70.7734 68.3982 73.8437 73.2472 75.6378L73.3016 75.6581L92.6744 82.6771C95.575 83.7281 97.8595 86.0054 98.9135 88.896L105.957 108.209L105.978 108.263C107.777 113.094 111.016 117.262 115.261 120.205C119.507 123.148 124.556 124.727 129.729 124.727C134.902 124.727 139.951 123.148 144.197 120.205C148.443 117.262 151.681 113.094 153.48 108.263L153.521 108.155L160.545 88.8977C161.599 86.0081 163.882 83.7316 166.782 82.6805C176.525 79.148 187.434 82.5762 193.381 91.039L223.505 133.91C223.516 133.925 223.524 133.942 223.534 133.957C228.045 140.476 226.441 149.411 219.921 153.96L117.032 225.751C111.613 229.533 110.798 237.692 115.213 243.976C119.63 250.261 127.604 252.292 133.024 248.51L239.241 174.706C245.791 170.156 254.802 171.748 259.381 178.266C263.973 184.801 262.368 193.81 255.801 198.374L149.632 272.144C132.954 283.78 108.421 277.536 94.8322 258.199C93.5324 256.349 92.381 254.445 91.3741 252.506C91.3172 252.396 91.1589 252.398 91.1049 252.509C91.055 252.612 90.9129 252.623 90.8473 252.53L3.77438 128.615C-2.83414 119.21 -0.539816 106.247 8.89813 99.6622L21.4057 90.9343C21.4336 90.9148 21.472 90.9217 21.4914 90.9496C21.513 90.9807 21.5574 90.985 21.5848 90.9588C21.9663 90.5947 22.3802 90.2545 22.8263 89.9432L57.6541 65.6418Z" fill="currentColor" /> <path d="M184.781 55.435C184.793 57.0601 184.298 58.6488 183.363 59.9801C182.428 61.3115 181.1 62.3194 179.564 62.8638L160.243 69.8673C152.51 72.6702 146.42 78.741 143.609 86.4472L136.586 105.703C136.021 107.22 135.004 108.528 133.672 109.451C132.34 110.375 130.756 110.87 129.133 110.87C127.51 110.87 125.926 110.375 124.594 109.451C123.262 108.528 122.245 107.22 121.68 105.703L114.657 86.4455C111.846 78.7374 105.754 72.6654 98.0192 69.8629L78.7019 62.8638C77.1805 62.3009 75.8684 61.2874 74.9418 59.9594C74.0152 58.6314 73.5186 57.0526 73.5186 55.435C73.5186 53.8174 74.0152 52.2386 74.9418 50.9106C75.8684 49.5826 77.1805 48.5691 78.7019 48.0062L98.0192 41.0071C105.754 38.2046 111.846 32.1326 114.657 24.4245L121.68 5.16662C122.245 3.65013 123.262 2.34224 124.594 1.41864C125.926 0.49505 127.51 0 129.133 0C130.756 0 132.34 0.49505 133.672 1.41864C135.004 2.34224 136.021 3.65013 136.586 5.16662L143.613 24.4281C146.424 32.1342 152.515 38.2044 160.248 41.0066L179.564 48.0062C181.1 48.5506 182.428 49.5585 183.363 50.8899C184.298 52.2213 184.793 53.8099 184.781 55.435Z" fill="currentColor" /> </svg>{/snippet}
{#snippet visaLogo()} <svg aria-hidden="true" width="50" height="16" viewBox="0 0 72 23" fill="none" xmlns="http://www.w3.org/2000/svg" class="h-4 w-auto text-neutral-950/85 dark:text-white/90" > <path d="M35.6495 0.413261L30.841 22.6604H25.0219L29.8376 0.413261H35.6495ZM60.1288 14.7776L63.1897 6.42214L64.9541 14.7776H60.1288ZM66.6178 22.6604H72L67.3044 0.413261H62.3374C62.3302 0.413261 62.3206 0.413261 62.3134 0.413261C61.2115 0.413261 60.2657 1.08065 59.8672 2.02829L59.86 2.04492L51.1336 22.6604H57.2409L58.4556 19.3353H65.9192L66.6178 22.6604ZM51.4337 15.3975C51.4577 9.52396 43.2259 9.20095 43.2835 6.57652C43.3028 5.7785 44.0686 4.92823 45.749 4.7121C46.0611 4.68123 46.4212 4.66223 46.7861 4.66223C48.4929 4.66223 50.111 5.04698 51.5514 5.73575L51.4865 5.70725L52.5068 0.988022C50.8912 0.368134 49.0211 0.00712515 47.067 0H47.0646C41.3126 0 37.2675 3.02819 37.2315 7.35791C37.1955 10.5595 40.1195 12.3431 42.3257 13.4119C44.5943 14.5021 45.3553 15.2027 45.3433 16.1741C45.3289 17.6704 43.538 18.3259 41.8624 18.352C41.7855 18.3544 41.6919 18.3544 41.6007 18.3544C39.5097 18.3544 37.5412 17.8343 35.8224 16.9151L35.8872 16.946L34.8333 21.8196C36.7202 22.5677 38.9072 23 41.1974 23C41.2334 23 41.2694 23 41.3054 23H41.3006C47.4126 23 51.4097 20.0146 51.4313 15.3903L51.4337 15.3975ZM27.3361 0.413261L17.9112 22.6604H11.7607L7.1227 4.90211C7.03388 4.03759 6.49853 3.31557 5.75433 2.95456L5.73993 2.94744C4.08829 2.14467 2.16778 1.49153 0.158443 1.08065L0 1.05452L0.139237 0.410885H10.0395C11.3886 0.410885 12.5097 1.38703 12.7186 2.66243L12.721 2.67668L15.172 15.5518L21.2265 0.408509L27.3361 0.413261Z" fill="currentColor" /> </svg>{/snippet}
<div class="flex min-h-80 items-center justify-center"> <TiltCard tiltLimit={10} scale={1.05} perspective={1200} class="flex aspect-video w-90 cursor-pointer flex-col justify-between overflow-hidden rounded-2xl bg-linear-to-br from-neutral-100 via-neutral-200 to-neutral-300 p-6 shadow-[0px_8px_16px_rgba(0,0,0,0.08),0px_16px_32px_rgba(0,0,0,0.06),0px_24px_48px_rgba(0,0,0,0.04),inset_0_0_0_1px_rgba(0,0,0,0.06)] dark:from-neutral-700 dark:via-neutral-800 dark:to-neutral-900 dark:shadow-[0px_8px_16px_rgba(0,0,0,0.3),0px_16px_32px_rgba(0,0,0,0.2),0px_24px_48px_rgba(0,0,0,0.1),inset_0_0_0_1px_rgba(255,255,255,0.06)]" > <div class="flex items-start justify-between"> {@render spellLogo()} {@render visaLogo()} </div>
<div class="flex items-end justify-between"> <div> <p class="text-muted-foreground text-xs">John Doe</p> <p class="font-mono text-sm font-medium tracking-tight tabular-nums"> 5367 4567 8901 2345 </p> </div> <div class="text-left"> <p class="text-muted-foreground text-xs">Exp.</p> <p class="font-mono text-sm font-medium tabular-nums">12/25</p> </div> </div> </TiltCard></div>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/s/tilt-card.json
Copy the Source Code
Copy and paste the following code into your project:
tilt-card.svelte
<script lang="ts"> import { cn } from "#lib/utils.js"; import type { Snippet } from "svelte"; import type { ClassValue, HTMLAttributes } from "svelte/elements";
type TiltEffect = "gravitate" | "evade";
interface Props extends HTMLAttributes<HTMLDivElement> { tiltLimit?: number; scale?: number; perspective?: number; effect?: TiltEffect; spotlight?: boolean; children?: Snippet; class?: ClassValue; style?: string; }
let { tiltLimit = 15, scale = 1.05, perspective = 1200, effect: tiltEffect = "evade", spotlight = true, children, class: className, style, ...restProps }: Props = $props();
let isHovered = $state(false); let pointerX = $state(0.5); let pointerY = $state(0.5);
function buildTransform(rotateX: number, rotateY: number, scaleValue: number) { return `perspective(${perspective}px) rotateX(${rotateX}deg) rotateY(${rotateY}deg) scale3d(${scaleValue}, ${scaleValue}, ${scaleValue})`; }
function clamp(value: number, min: number, max: number) { return Math.min(Math.max(value, min), max); }
function handlePointerMove(event: PointerEvent) { const element = event.currentTarget as HTMLDivElement | null;
if (!element) return;
const rect = element.getBoundingClientRect(); if (rect.width === 0 || rect.height === 0) return;
pointerX = clamp((event.clientX - rect.left) / rect.width, 0, 1); pointerY = clamp((event.clientY - rect.top) / rect.height, 0, 1); }
function handlePointerEnter() { isHovered = true; }
function handlePointerLeave() { isHovered = false; }
let transform = $derived.by(() => { if (!isHovered) { return buildTransform(0, 0, 1); }
const direction = tiltEffect === "evade" ? -1 : 1; const rotateX = (pointerY - 0.5) * (tiltLimit * 2) * direction; const rotateY = (pointerX - 0.5) * -(tiltLimit * 2) * direction;
return buildTransform(rotateX, rotateY, scale); });
let rootStyle = $derived( `transform: ${transform}; transition: transform 0.2s ease-out; transform-style: preserve-3d; ${style ?? ""}` ); let spotlightLeft = $derived(`${pointerX * 100}%`); let spotlightTop = $derived(`${pointerY * 100}%`);</script>
<div class={cn("relative overflow-hidden will-change-transform", className)} style={rootStyle} onpointerenter={handlePointerEnter} onpointermove={handlePointerMove} onpointerleave={handlePointerLeave} {...restProps}> {@render children?.()}
{#if spotlight} <div class="pointer-events-none absolute inset-0 z-10 overflow-hidden" style="opacity: {isHovered ? 1 : 0}; transition: opacity 0.3s;" > <div class="absolute h-[200%] w-[200%] rounded-full opacity-100 dark:opacity-60" style="left: {spotlightLeft}; top: {spotlightTop}; transform: translate(-50%, -50%); transition: left 0.2s ease-out, top 0.2s ease-out; background: radial-gradient(circle, rgba(255,255,255,0.15) 0%, transparent 40%);" ></div> </div> {/if}</div> index.ts
import TiltCard from "./tilt-card.svelte";export { TiltCard };Folder Structure
Folder Structure
src/└── lib/ └── components/ └── spell/ └── tilt-card/ ├── tilt-card.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/spell/tilt-card/llms.txt
Follow the guide's installation and usage instructions.Match the project's existing structure, imports, and styles.Keep changes scoped to the component and verify it works.Reply with a short bullet list of completed changes.Usage
<script lang="ts"> import { TiltCard } from "#lib/components/spell/tilt-card/index.js";</script>
<TiltCard> <div class="rounded-xl border p-8">Hover me</div></TiltCard>Props
| Name | Type | Default | Description |
|---|---|---|---|
tiltLimit | number | 15 | Sets the maximum rotation angle in degrees on both axes. |
scale | number | 1.05 | Controls how much the card scales up while hovered. |
perspective | number | 1200 | Sets the CSS perspective distance used for the 3D depth effect. |
effect | "gravitate" | "evade" | "evade" | Determines whether the card tilts away from the cursor or follows it. |
spotlight | boolean | true | Toggles the radial highlight overlay that tracks the pointer position. |
class | ClassValue | undefined | Custom classes applied to the root tilt wrapper. |
style | string | undefined | Inline styles appended to the root wrapper. |