Tilt Card
Preview
Tilt me
Move your cursor across the card to see 3D tilt + glare.
<script setup lang="ts">
import { TiltCard } from 'beui-vue'
</script>
<template>
<div class="tilt-demo">
<TiltCard class="tilt-sample">
<div class="eyebrow">Premium</div>
<h3>Tilt me</h3>
<p>Move your cursor across the card to see 3D tilt + glare.</p>
</TiltCard>
</div>
</template>
<style scoped>
.tilt-demo { display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.tilt-sample { width: 280px; padding: 2rem; border: 1px solid var(--beui-border); background: var(--beui-card); }
.eyebrow { color: var(--beui-muted-foreground); font-size: .75rem; line-height: 1rem; letter-spacing: .05em; text-transform: uppercase; }
/* The docs theme styles bare h3/p inside page content; keep this demo's own type scale. */
.tilt-sample h3 { margin: .5rem 0 0; padding: 0; border: 0; color: var(--beui-foreground); font-size: 1.5rem; line-height: 2rem; font-weight: 600; }
.tilt-sample p { margin: .75rem 0 0; color: var(--beui-muted-foreground); font-size: .875rem; line-height: 1.25rem; }
</style><script setup lang="ts">
import { motion, useMotionTemplate, useMotionValue, useSpring } from 'motion-v'
import { useReducedMotion } from '../core/reduced-motion'
import { useTemplateRef } from 'vue'
import { useMountedMedia } from '../core/mounted-media'
import { mouseSpring } from '../core/motion'
const props = withDefaults(defineProps<{ max?: number; glare?: boolean; className?: string }>(), { max: 12, glare: true })
const target = useTemplateRef<{ $el?: HTMLElement } | HTMLElement>('target')
const reduce = useReducedMotion()
// Decorative cursor-follow: skip on touch (phantom hover) and reduced motion.
const canHover = useMountedMedia('(hover: hover) and (pointer: fine)')
const enabled = () => !reduce.value && canHover.value
const rx = useMotionValue(0)
const ry = useMotionValue(0)
const gx = useMotionValue(50)
const gy = useMotionValue(50)
const srx = useSpring(rx, mouseSpring)
const sry = useSpring(ry, mouseSpring)
const transform = useMotionTemplate`perspective(1000px) rotateX(${srx}deg) rotateY(${sry}deg)`
const glareBackground = useMotionTemplate`radial-gradient(circle at ${gx}% ${gy}%, var(--beui-foreground), transparent 50%)`
function move(event: PointerEvent) {
// A motion component ref is the component instance; the card element is its $el.
const element = (target.value && '$el' in target.value ? target.value.$el : target.value) as HTMLElement | null | undefined
if (!element || !enabled()) return
const rect = element.getBoundingClientRect()
const px = (event.clientX - rect.left) / rect.width
const py = (event.clientY - rect.top) / rect.height
ry.set((px - .5) * props.max)
rx.set((.5 - py) * props.max)
gx.set(px * 100)
gy.set(py * 100)
}
function leave() {
rx.set(0)
ry.set(0)
}
</script>
<template>
<motion.div
ref="target"
class="be-tilt"
:class="className"
:style="{ transform, transformStyle: 'preserve-3d' }"
@pointermove="move"
@pointerleave="leave"
>
<slot />
<motion.div v-if="glare && canHover && !reduce" aria-hidden="true" class="be-tilt-glare" :style="{ background: glareBackground }" />
</motion.div>
</template>
<style scoped>
.be-tilt { position: relative; overflow: hidden; border-radius: 1rem; will-change: transform; }
.be-tilt-glare { position: absolute; inset: 0; pointer-events: none; opacity: .15; }
</style>Install
Add it with your package manager, or copy the source manually.
Run it in a project set up with shadcn-vue. The source is copied to components/beui and its dependencies are added to your package.json. Read the shadcn-vue guide
$ bunx --bun shadcn-vue@latest add @beui-vue/tilt-card$ bun add beui-vueDownload the release archive to your project root, then install the local file.
$ bun add ./beui-vue-0.1.0.tgzImport the shared styles once in your application.
import TiltCard from '@/components/beui/actions/TiltCard.vue'
import '@/components/beui/styles.css'API Reference
max?number12glare?booleantrueclassName?string—Related components
Marquee
Infinite horizontal or vertical scroll with pause-on-hover.
Theme Toggle
Theme toggle button that repaints the whole page through the View Transition API: a rectangle or circle clip-path reveal, or slats that open across the screen like a shutter.
Shader Background
Canvas shader backgrounds (mesh gradient, grain, warp, waves, voronoi, dot orbit and more) with a single typed variant prop. Reduced-motion freezes animated variants.
Updated