Framer Motion Playground

Basics

Docs

initial: the state of our element at mount time.

animate: the state in which our element will be at the end of the animation.

transition: how our element goes from the initial state to the target state. This is where we can define which transition type we want to define, delays, or repetitions of the same transition.

Gestures

Docs

whileHover: the state of our element when the mouse is hovering over it.

whileTap: the state of our element when the mouse is clicking on it.

Variants

Docs

Instead of initial and animate, we can use variants to define different states for our element.

InView

Docs

useInView: a hook that returns a boolean value indicating whether the element is

whileInView: a prop that allows us to animate elements while they are in view.

inView? false

scroll down

Presense

Docs

AnimatePresense: a component that allows us to animate elements that are being added or removed from the DOM. Framer Motion will automatically detect and interpolate the changes between the old and new elements.

Stagger

Docs

staggerChildren: a prop that allows us to stagger the children of a container.

  1. Hi
  2. Hi

Motion values

Docs

Motion values: track the state and velocity of animating values.

Motion values can be created by using the useMotionValue hook

Motion values' state change can be adjusted by using hooks like useSpring or useTransform

Motion values can be used to animate any property of a component, not just CSS properties.

Motion values can be used to create custom animations, like the following example.

Drag the rectangle to see the animation

Drag

Docs

Add thedragprop to make an element draggable.

useDragControls: control the drag gesture.

dragConstraints: limit the drag gesture to a specific area.

x and y values of the drag gesture can be used to animate other properties.

Drag the rectangle (or drag the small circle)

Learning Resources

Framer Motion API : the official documentation for Framer Motion.

framer.com/api/motion/

Guide to creating animations that spark joy with Framer Motion

blog.maximeheckel.com

Satisfying Scroll Animations with Framer Motion

youtube.com

Framer Motion Examples

framer.com/motion/examples/