THE PLAYGROUND · CORE MOTION
Parallax
Layers move at different speeds to create a sense of depth.
ParallaxCore Motion · Layers move at different speeds to create a sense of depth. · Secondary effect: 3D tilt.
HOVER
46° 29′ N / 11° 51′ EThe Dolomites
1import { useState } from "react";2import { motion } from "motion/react";3 4const surface = { width: 100, height: 100, borderRadius: 16, background: "#b8ed79", display: "grid", placeItems: "center", color: "#141714" };5 6export default function ParallaxDemo() {7 const [pointer, setPointer] = useState({ x: 0, y: 0 });8 return <div onPointerMove={e => {9 const box = e.currentTarget.getBoundingClientRect();10 setPointer({ x: (e.clientX - box.left - box.width / 2) / box.width * 22, y: (e.clientY - box.top - box.height / 2) / box.height * 22 });11 }} onPointerLeave={() => setPointer({x: 0, y: 0})} style={{ width: 300, height: 220, perspective: 700 }}>12 <motion.div style={{...surface, position: "relative", width: 280, height: 180}} animate={{rotateY: pointer.x * 1, rotateX: -pointer.y * 1}} transition={{duration: .15}}>13 <span>Background layer</span>14 <motion.strong style={{position: "absolute", bottom: 20}} animate={{x: pointer.x * 1, y: pointer.y * 1}}>Foreground layer</motion.strong>15 </motion.div>16 </div>;17}Install: npm install motion. Move foreground layers further than the background. This compact example illustrates the core technique; the styled playground contains additional presentation details.