Tilt Card
wise-ui/tilt-cardFreeComponent
A card that tilts toward the cursor with a 3D perspective effect.
Live preview
live · rendered by the registry
Rendered by wise-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://wise-ui.com/r/tilt-card.jsonSource
1"use client"23import * as React from "react"4import {5 motion,6 useMotionValue,7 useSpring,8 useTransform,9} from "motion/react"10import { cn } from "@/registry/wise-ui/lib/utils"1112interface TiltCardProps {13 tiltMax?: number14 glare?: boolean15 glareOpacity?: number16 scale?: number17 perspective?: number18 children: React.ReactNode19 className?: string20}2122const springConfig = { stiffness: 300, damping: 20, mass: 0.5 }2324function TiltCard({25 tiltMax = 15,26 glare = true,27 glareOpacity = 0.15,28 scale = 1.02,29 perspective = 1000,30 children,31 className,32}: TiltCardProps) {33 const ref = React.useRef<HTMLDivElement>(null)3435 const rawX = useMotionValue(0)36 const rawY = useMotionValue(0)37 const rawScale = useMotionValue(1)3839 const rotateX = useSpring(rawX, springConfig)40 const rotateY = useSpring(rawY, springConfig)41 const springScale = useSpring(rawScale, springConfig)4243 const glareX = useMotionValue(50)44 const glareY = useMotionValue(50)4546 const glareBackground = useTransform(47 [glareX, glareY],48 ([x, y]) =>49 `radial-gradient(circle at ${x}% ${y}%, rgba(255,255,255,${glareOpacity}), transparent 60%)`50 )5152 function handleMouseMove(e: React.MouseEvent<HTMLDivElement>) {53 const el = ref.current54 if (!el) return55 const rect = el.getBoundingClientRect()56 const centerX = rect.left + rect.width / 257 const centerY = rect.top + rect.height / 258 const offsetX = (e.clientX - centerX) / (rect.width / 2)59 const offsetY = (e.clientY - centerY) / (rect.height / 2)6061 rawX.set(offsetY * tiltMax)62 rawY.set(-offsetX * tiltMax)6364 // Glare follows mouse position as percentage65 glareX.set(((e.clientX - rect.left) / rect.width) * 100)66 glareY.set(((e.clientY - rect.top) / rect.height) * 100)67 }6869 function handleMouseEnter() {70 rawScale.set(scale)71 }7273 function handleMouseLeave() {74 rawX.set(0)75 rawY.set(0)76 rawScale.set(1)77 glareX.set(50)78 glareY.set(50)79 }8081 return (82 <motion.div83 ref={ref}84 className={cn("relative", className)}85 style={{86 perspective,87 transformStyle: "preserve-3d",88 rotateX,89 rotateY,90 scale: springScale,91 }}92 onMouseMove={handleMouseMove}93 onMouseEnter={handleMouseEnter}94 onMouseLeave={handleMouseLeave}95 >96 {children}97 {glare && (98 <motion.div99 className="pointer-events-none absolute inset-0 rounded-[inherit] z-10"100 style={{ background: glareBackground }}101// … truncated
What it pulls in
npm packages
Files it writes
More from wise-ui
All 20 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Animated Tabsanimated-tabs | wise-ui | Components | Free | 3 deps | |
| Border Beamborder-beam | wise-ui | Components | Free | 3 deps | |
| Data Tabledata-table | wise-ui | Components | Free | 3 deps | |
| Dockdock | wise-ui | Components | Free | 3 deps | |
| Dot Matrixdot-matrix | wise-ui | Components | Free | 2 deps | |
| Editable Texteditable-text | wise-ui | Components | Free | 4 deps | |
| Gradient Sidebargradient-sidebar | wise-ui | Components | Free | 3 deps | |
| Kanban Boardkanban-board | wise-ui | Components | Free | 6 deps |
