✓ Recommended by FindUtils

Framer Motion Animation Patterns

Production-ready animations with Framer Motion for React including gestures, layout, and scroll.

Claude CodeCursorGitHub CopilotWindsurfClineCodex / OpenAIGemini CLI
Updated 2026-04-05
CLAUDE.md
# Framer Motion Animation Patterns

You are an expert in Framer Motion, React animation, and motion design.

Core Animation:
- Use `<motion.div>` wrapper for any HTML/SVG element
- Animate with `animate` prop: `<motion.div animate={{ opacity: 1, y: 0 }} />`
- Set `initial` for starting state: `initial={{ opacity: 0, y: 20 }}`
- Use `transition` to control timing: `transition={{ duration: 0.3, ease: 'easeOut' }}`
- Spring physics for natural motion: `transition={{ type: 'spring', stiffness: 300, damping: 30 }}`

Variants:
- Define animation states as named variants for complex orchestration
- `variants={{ hidden: { opacity: 0 }, visible: { opacity: 1 } }}`
- Orchestrate children with `staggerChildren` and `delayChildren` in parent transition
- Use `whileHover`, `whileTap`, `whileFocus` for interaction states
- Animate based on data: pass variant name dynamically `animate={isOpen ? 'open' : 'closed'}`

Layout Animations:
- Add `layout` prop for automatic layout transition animations
- Use `layoutId` to animate elements between different components (shared layout)
- Wrap layout animations in `<LayoutGroup>` to scope shared layouts
- Use `layout="position"` to only animate position, not size

Gestures:
- Drag: `<motion.div drag dragConstraints={{ left: 0, right: 300 }} />`
- Use `dragElastic` for bounce-back feel, `dragMomentum` for throw physics
- Pan gesture: `onPan={(event, info) => {}}` for custom pan handling
- Use `useMotionValue()` for imperative control without re-renders

Scroll:
- `useScroll()` tracks scroll position: `const { scrollY, scrollYProgress } = useScroll()`
- Use `useTransform()` to map scroll progress to animation values
- Scroll-triggered animations: `whileInView={{ opacity: 1 }}` with `viewport` options
- `useInView()` hook for conditional rendering based on viewport visibility

Performance:
- Animate transform and opacity only — avoid animating layout properties
- Use `useMotionValue` + `useTransform` to bypass React re-renders
- Set `layout` only on elements that actually change position
- Use `AnimatePresence` with `mode="wait"` for exit animations before enter

Add to your project root CLAUDE.md file, or append to an existing one.

Tags

framer-motionanimationreactgestureslayoutscroll