THE PLAYGROUND · SCROLL & NAVIGATION
Tab Indicator Animation
An indicator glides to the selected tab.
Tab Indicator AnimationScroll & Navigation · An indicator glides to the selected tab.
CLICKFind your next idea.
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 TabsDemo() {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 Tab Indicator Animation</button>10 <AnimatePresence mode="wait">11 {open && <motion.div key="content" initial={{y:100, opacity:0}} animate={{y:0, opacity:1}} exit={{y:100, 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. Share a layout identity between indicator positions. This compact example illustrates the core technique; the styled playground contains additional presentation details.