Member-only story

Framer Motion — Keyframes and Gestures

John Au-Yeung
3 min readFeb 10, 2021

--

Photo by pine watt on Unsplash

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.

Animation

We can use the animate prop to specify how to animate an element.

For example, we can write:

import React from "react";
import { motion } from "framer-motion";
export default function App() {
return (
<motion.div
style={{ backgroundColor: "red", width: 100, height: 100 }}
animate={{ scale: 2 }}
transition={{ duration: 0.5 }}
/>
);
}

We set animate to { scale: 2 } to double the size of the div.

The transition component is set to { duration: 0.5 } to set the duration of the animation in seconds.

Keyframes

We can add keyframes to create more complex animations.

For example, we can write:

import React from "react";
import { motion } from "framer-motion";
export default function App() {
return (
<motion.div
style={{ backgroundColor: "red", width: 100, height: 100 }}
animate={{
scale: [1, 2, 2, 1, 1],
rotate: [0, 0, 270, 270, 0]…

--

--

No responses yet