Member-only story
Framer Motion — Exit Animation and Staggering Animations
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.
Exit Animations
We can add exit animation with Framer Motion.
For example, we can write:
import React from "react";
import { motion, AnimatePresence } from "framer-motion";const image = {
src:
"https://i.picsum.photos/id/23/200/300.jpg?hmac=NFze_vylqSEkX21kuRKSe8pp6Em-4ETfOE-oyLVCvJo"
};export const Slideshow = ({ image }) => (
<AnimatePresence>
<motion.img
key={image.src}
src={image.src}
initial={{ opacity: 0, y: 200 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
/>
</AnimatePresence>
);export default function App() {
return (
<>
<Slideshow image={image} />
</>
);
}
We use the AnimatePresence
component to enclose the motion.img
component to show animation on the image when it’s being unloaded.
We set the inital
and animate
props to set the starting and ending styles respectively.
And we have the exit
prop to set the style to show after animating.