Back to Explore
THE PLAYGROUND · SCROLL & NAVIGATION

Page Transition

The outgoing view makes way for the next view.

Page TransitionScroll & Navigation · The outgoing view makes way for the next view.
CLICK
STEP 01 / DISCOVERStart with an idea.
CLICK TO REPLAY · 600 ms
1import { useState } from "react";2import { motion, AnimatePresence } from "motion/react";3 4const surface = { width: 100, height: 100, borderRadius: 16, background: "#b8ed79", display: "grid", placeItems: "center", color: "#141714" };5 6export default function PageDemo() {7  const [open, setOpen] = useState(false);8  return <div style={{position: "relative", width: 320, minHeight: 200, overflow: "hidden"}}>9    <button aria-expanded={open} onClick={() => setOpen(v => !v)}>Toggle Page Transition</button>10    <AnimatePresence mode="wait">11      {open && <motion.div key="content" initial={{x:80, opacity:0}} animate={{x:0, opacity:1}} exit={{x:-80, opacity:0}} transition={{ duration: 0.6, delay: 0, ease: "easeInOut" }} style={{...surface, width: 300, height: "auto", padding: 20}}>12        <p>Details and actions</p><button onClick={() => setOpen(false)}>Close</button>13      </motion.div>}14    </AnimatePresence>15  </div>;16}

Install: npm install motion. Keep transitions quick and preserve reading order. This compact example illustrates the core technique; the styled playground contains additional presentation details.