Open In App

Framer-Motion Introduction and Installation

Framer-motion is an open-source, production-ready animation and gesture library for React. It provides a low-level API to simplify animation and gesture integration into the application while maintaining HTML and SVG semantics.

Features:



Additionally,

Note: It requires React 16.8 or the higher versions to use Motion.



Components:

Let’s see a simple animation using Framer-motion and ReactJs.

Creating React Application: Create a React application using the following command: 

npx create-react-app demo

Project Structure: The project should look like this:

Example: Now, import motion from the framer-motion in the App.js  and add animation to a div element. Here, we will scale the div while hovering.




import React from "react";
import { motion } from "framer-motion";
  
function App() {
    return (
        <motion.div style={{
            color: 'green',
            fontSize: 20,
            width: '300px',
            height: '30px',
            textAlign: 'center',
            border: '2px solid green',
            margin: '40px'
        }}
  
            whileHover={{ scale: 0.5 }}
        >
            GeeksforGeeks
        </motion.div>
    );
}
  
export default App;

Start the application: You can run the server up by the following command:

npm start

Output:


Article Tags :