"use client"; import { motion, useMotionValue, useSpring, useTransform } from "framer-motion"; type StackItem = { id: string; imageUrl: string; prompt: string; modelId: string; }; export function HoverStack({ items }: { items: StackItem[] }) { const offsetX = useMotionValue(0); const offsetY = useMotionValue(0); const smoothX = useSpring(offsetX, { stiffness: 180, damping: 20, mass: 0.5 }); const smoothY = useSpring(offsetY, { stiffness: 180, damping: 20, mass: 0.5 }); const rotateY = useTransform(smoothX, [-160, 160], [-8, 8]); const rotateX = useTransform(smoothY, [-120, 120], [7, -7]); const cards = items.slice(0, 3); if (cards.length === 0) { return (
暂无可展示样例
); } return ( { offsetX.set(0); offsetY.set(0); }} onMouseMove={(event) => { const rect = event.currentTarget.getBoundingClientRect(); const x = event.clientX - (rect.left + rect.width / 2); const y = event.clientY - (rect.top + rect.height / 2); offsetX.set(x); offsetY.set(y); }} style={{ rotateX, rotateY, transformStyle: "preserve-3d" }} > {cards.map((item, index) => { const offset = index * 18; return ( {item.prompt}

{item.prompt}

{item.modelId}

); })}
); }