![]() |
VOOZH | about |
Framer Motion is an open-source animation and gesture library for React, offering a high-level API for adding smooth animations and gestures. It works with React to create smooth animations and dynamic user interactions.
Here are the steps to install and implement Framer Motion.
Create a React application using the following command.
npx create-react-app demo
cd demo
First, ensure that you have the Framer Motion library installed. Open your terminal and run the following command:
npm install framer-motionIn your App.js file, you need to import the motion component from the framer-motion library to animate the elements.
import { motion } from "framer-motion";You can now replace your standard JSX tags with their animated versions provided by Framer Motion. In this example, we are using <motion.div> instead of <div>. This allows us to apply animations to the <div> element.
Framer Motion simplifies interactive animations. In this example, the whileHover animation scales the element down on hover.
Final App.js file
Output:
Framer Motion offers event handlers to control and trigger actions during animations, giving more control over their lifecycle. Here are some key Framer Motion events:
The onAnimationComplete event is triggered when an animation finishes. It allows you to perform actions after the animation, such as navigating to a new page, displaying a success message, or starting another animation.
The onUpdate event is triggered continuously during an animation's lifecycle. It enables real-time tracking of animation progress or updates, such as dynamically adjusting a progress bar based on the animation's values.
These events are triggered when the user interacts with an element by hovering over it (onHoverStart) and when the user stops hovering (onHoverEnd).
These events are triggered during tap gestures on mobile devices, but they can also be used for clicks on any device.
These events are used with draggable elements. They allow you to handle the start, movement, and end of dragging actions.
Framer Motion offers components for smooth animations and interactions in React apps.