← All writing

Frontend· November 5, 2024 · 11 min

Framer Motion Masterclass: Animations That Feel Alive

Advanced patterns for spring physics, gesture interactions, layout animations, and shared-element transitions that make your UI feel magical.

Why Spring Physics

CSS transitions use easing curves. They feel mechanical because they are mathematical functions — the animation always ends at exactly the same time regardless of velocity.

Spring physics simulate a real spring: the animation responds to velocity and can overshoot, settle, and feel alive.

<motion.div
  animate={{ x: 100 }}
  transition={{ type: 'spring', stiffness: 300, damping: 20 }}
/>

Higher stiffness = snappier. Lower damping = more bounce.

Layout Animations

Framer Motion's layout prop automatically animates position and size changes — even across re-renders caused by conditional rendering.

<motion.div layout>
  {isExpanded && <ExpandedContent />}
</motion.div>

This is how you get those satisfying "morphing card" effects without calculating positions manually.

Shared Element Transitions

layoutId creates shared element transitions — the same visual element animating between two different components.

{/* List item */}
<motion.div layoutId={`card-${id}`} />

{/* Modal */}
<motion.div layoutId={`card-${id}`} />

When the modal opens, Framer Motion smoothly animates the card from its list position to its modal position.

Gesture Interactions

<motion.div
  whileHover={{ scale: 1.05 }}
  whileTap={{ scale: 0.97 }}
  drag
  dragConstraints={{ left: -100, right: 100 }}
/>

These are declarative — no event handlers needed.