Member-only story
Framer Motion — Animations and Gestures
3 min readFeb 10, 2021
With the Framer Motion library, we can render animations in our React app easily.
In this article, we’ll take a look at how to get started with Framer Motion.
Motion Components
We can add motion components to add elements that we can animate.
For example, we can write:
import React from "react";
import { motion } from "framer-motion";export default function App() {
return (
<div className="App">
<motion.div
animate={{ scale: 0.5 }}
style={{ backgroundColor: "red", width: 100, height: 100 }}
/>
</div>
);
}
to create a div that shrinks to half of the size that is specified in the style
prop.
scale
set to 0.5 does the shrinking with animation.
Animation
The animate
prop lets us animate an element.
For example, we can write:
import React from "react";
import { motion } from "framer-motion";export default function App() {
const variants = {
hidden: { opacity: 0 },
visible: { opacity: 1 }
}; return (
<motion.div
initial="hidden"
animate="visible"…