Top Related Projects
JavaScript animation engine
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
✌️ A spring physics based React animation library
🎊 A collection of animations for inline style libraries
Quick Overview
Framer Motion is a production-ready motion library for React. It provides a simple and powerful API for adding animations and gestures to React applications, making it easy to create fluid and interactive user interfaces.
Pros
- Easy to use with a declarative API that integrates seamlessly with React components
- Supports a wide range of animation types, including keyframes, springs, and gestures
- Offers excellent performance optimization with automatic batching and hardware acceleration
- Provides a comprehensive set of animation controls, including pause, resume, and reverse
Cons
- Can increase bundle size, which may impact initial load times for smaller applications
- Learning curve for more advanced features and complex animations
- Limited browser support for older versions (IE11 and below)
- Some users report occasional issues with TypeScript definitions
Code Examples
- Basic animation:
import { motion } from "framer-motion"
function AnimatedBox() {
return (
<motion.div
initial={{ opacity: 0, scale: 0.5 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ duration: 0.5 }}
/>
)
}
- Gesture animation:
import { motion } from "framer-motion"
function DraggableBox() {
return (
<motion.div
drag
dragConstraints={{ left: -100, right: 100, top: -100, bottom: 100 }}
whileDrag={{ scale: 1.1 }}
/>
)
}
- Variants for orchestrating animations:
import { motion } from "framer-motion"
const list = {
visible: { opacity: 1, transition: { staggerChildren: 0.1 } },
hidden: { opacity: 0 },
}
const item = {
visible: { opacity: 1, x: 0 },
hidden: { opacity: 0, x: -100 },
}
function AnimatedList() {
return (
<motion.ul initial="hidden" animate="visible" variants={list}>
{[0, 1, 2, 3].map((index) => (
<motion.li key={index} variants={item} />
))}
</motion.ul>
)
}
Getting Started
To start using Framer Motion in your React project:
-
Install the package:
npm install framer-motion
-
Import and use in your React component:
import { motion } from "framer-motion" function MyComponent() { return ( <motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} > Hello, Framer Motion! </motion.div> ) }
-
For more advanced usage, refer to the Framer Motion documentation.
Competitor Comparisons
JavaScript animation engine
Pros of Anime
- Lightweight and fast, with a smaller file size
- Supports a wider range of animation targets, including SVG and CSS properties
- Easier to create complex animation timelines
Cons of Anime
- Less integrated with React ecosystem
- Fewer built-in animation variants and presets
- Limited support for gesture-based animations
Code Comparison
Anime:
anime({
targets: '.element',
translateX: 250,
rotate: '1turn',
duration: 800,
easing: 'easeInOutQuad'
});
Motion:
<motion.div
animate={{ x: 250, rotate: 360 }}
transition={{ duration: 0.8, ease: "easeInOut" }}
/>
Both libraries offer declarative ways to create animations, but Motion is more tightly integrated with React components. Anime provides a more traditional JavaScript approach, while Motion leverages React's component structure for animations.
Motion excels in React-based projects, offering seamless integration with components and hooks. It provides a more intuitive API for React developers and includes features like gesture animations and layout transitions.
Anime, on the other hand, is more versatile and can be used in various JavaScript environments. It offers fine-grained control over animations and is particularly strong in creating complex animation timelines.
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
Pros of GSAP
- More extensive feature set, including advanced timeline control and complex animations
- Better cross-browser compatibility, especially for older browsers
- Higher performance for complex animations with many elements
Cons of GSAP
- Steeper learning curve due to its extensive API
- Larger file size, which may impact load times for smaller projects
- Commercial license required for some advanced features
Code Comparison
Motion:
<motion.div
initial={{ opacity: 0, scale: 0.5 }}
animate={{ opacity: 1, scale: 1 }}
transition={{ duration: 0.5 }}
>
Hello World
</motion.div>
GSAP:
gsap.to(".box", {
duration: 0.5,
opacity: 1,
scale: 1,
ease: "power2.out"
});
Both Motion and GSAP are powerful animation libraries for web development. Motion is part of the Framer framework and offers a more React-centric approach with a declarative API. It's easier to learn and integrate into React projects. GSAP, on the other hand, is a more established and feature-rich library that works well with any JavaScript framework or vanilla JS. It offers more fine-grained control over animations but comes with a steeper learning curve. The choice between the two often depends on the project requirements, performance needs, and developer preferences.
✌️ A spring physics based React animation library
Pros of react-spring
- More flexible and customizable, allowing for complex physics-based animations
- Generally lighter weight and potentially better performance for complex animations
- Supports a wider range of platforms, including React Native
Cons of react-spring
- Steeper learning curve, especially for developers new to spring physics
- Less intuitive API for simple animations compared to Framer Motion
- Fewer built-in animation presets and helpers
Code Comparison
react-spring:
import { useSpring, animated } from 'react-spring'
const AnimatedComponent = () => {
const props = useSpring({ opacity: 1, from: { opacity: 0 } })
return <animated.div style={props}>I will fade in</animated.div>
}
Framer Motion:
import { motion } from 'framer-motion'
const AnimatedComponent = () => {
return <motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }}>I will fade in</motion.div>
}
Both libraries offer powerful animation capabilities for React applications. react-spring excels in complex, physics-based animations and cross-platform support, while Framer Motion provides a more intuitive API and better built-in features for simpler animations. The choice between them often depends on the specific project requirements and developer preferences.
🎊 A collection of animations for inline style libraries
Pros of react-animations
- Lightweight and focused solely on CSS animations
- Easy to integrate with existing CSS-in-JS solutions
- Provides a set of predefined animations out of the box
Cons of react-animations
- Limited to CSS animations, lacking advanced features like gestures or physics-based animations
- Less active development and community support
- No built-in components or hooks for animation control
Code Comparison
react-animations:
import { fadeIn } from 'react-animations';
import styled, { keyframes } from 'styled-components';
const fadeInAnimation = keyframes`${fadeIn}`;
const FadeInDiv = styled.div`animation: 1s ${fadeInAnimation};`;
motion:
import { motion } from "framer-motion";
const FadeInDiv = () => (
<motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} transition={{ duration: 1 }}>
Content
</motion.div>
);
Summary
react-animations is a lightweight library focused on CSS animations, making it easy to use with CSS-in-JS solutions. However, it lacks advanced features and has less community support compared to motion. motion offers a more comprehensive animation solution with advanced features like gestures and physics-based animations, but may be overkill for simple use cases. The code comparison shows that react-animations requires additional setup with styled-components, while motion provides a more declarative API with built-in components.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Framer Motion
An open source motion library for React, made by Framer.
Motion powers Framer, the web builder for creative pros. Design and ship your dream site. Zero code, maximum speed.
This repo contains the source code for Framer Motion and Framer Motion 3D.
ð Docs
- Install
framer-motion
via your package manager. - Check out our documentation for guides and a full API reference.
- Or see our examples for inspiration.
ð Contribute
- Want to contribute to Framer Motion? Our contributing guide has you covered.
ð©ð»ââï¸ License
- Framer Motion is MIT licensed.
⨠Framer
- Design and publish sites that inspire. Try Framer for free.
Top Related Projects
JavaScript animation engine
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
✌️ A spring physics based React animation library
🎊 A collection of animations for inline style libraries
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot