Convert Figma logo to code with AI

motiondivision logomotion

A modern animation library for React and JavaScript

29,019
976
29,019
293

Top Related Projects

61,908

JavaScript animation engine

22,258

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

  1. 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 }}
    />
  )
}
  1. 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 }}
    />
  )
}
  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:

  1. Install the package:

    npm install framer-motion
    
  2. 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>
      )
    }
    
  3. For more advanced usage, refer to the Framer Motion documentation.

Competitor Comparisons

61,908

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.

22,258

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Motion logo

Motion

An open source animation library for JavaScript, React and Vue.


Motion is an animation library and suite of developer tools for making beautiful animations.

It's the only library with first-class APIs for JS, React and Vue. It's also the only library with a hybrid engine, combining the power of JS animations with the performance of native browser APIs.

🍦 Flavours

JavaScript

import { animate } from "motion"

animate("#box", { x: 100 })

Get started with JavaScript.

React

import { motion } from "motion/react"

function Component() {
    return <motion.div animate={{ x: 100 }} />
}

Get started with Motion for React.

Vue

<script>
import { motion } from "motion-v"
</script>

<template>
  <motion.div :animate={{ x: 100 }} />
</template>

Get started with Motion for Vue.

🎨 Studio

Video of bezier curve editing

Motion Studio is a versatile suite of developer tools allowing you to:

  • Visually edit CSS and Motion easing curves in VS Code
  • Generate CSS springs with LLMs
  • Load Motion docs into your LLM

Get started with Motion Studio.

🎓 Examples

Motion Examples offers 100s of free and Motion+ examples for beginners and advanced users alike. Easy copy/paste code to kickstart your next project.

⚡️ Motion+

Motion+ is a one-time fee, lifetime membership that unlocks over 100 premium examples, early access, powerful Studio tools, a private Discord, and exclusive APIs like:

  • Cursor
  • Ticker
  • AnimateNumber
  • splitText

Get Motion+

👩🏻‍⚖️ License

  • Motion is MIT licensed.

💎 Contribute

✨ Sponsors

Motion is sustainable thanks to the kind support of its sponsors.

Partners

Framer

Motion powers Framer animations, the web builder for creative pros. Design and ship your dream site. Zero code, maximum speed.

Framer

Platinum

Tailwind Emil Kowalski Linear

Gold

Vercel Liveblocks Luma

Silver

Frontend.fyi Firecrawl Puzzmo Build UI

Personal

NPM DownloadsLast 30 Days