Motion Animation Library

12.38.0 · active · verified Sun Apr 19

Motion is a high-performance animation library designed for JavaScript, React, and Vue applications, currently at version 12.38.0. It offers a simple, declarative API that leverages a hybrid engine, combining JavaScript's flexibility with native browser APIs for GPU-accelerated, 120fps animations. Key differentiators include its production-readiness with comprehensive TypeScript support, extensive test suite, tree-shakability, and a tiny footprint. It provides a rich set of features out-of-the-box, such as gestures (drag), spring physics, layout transitions, scroll-linked effects, and animation timelines. While the core `motion` package targets vanilla JavaScript, it also provides specific packages and import paths for seamless integration with React (`motion/react`) and Vue (`motion-v`), making it a versatile choice for a wide range of web projects. Its evolution from Framer Motion signifies a streamlined approach to imports and usage across modern web frameworks.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic React component utilizing `motion.div` to create an interactive element that animates with a spring effect on hover, showcasing declarative animation syntax.

import { motion } from "motion/react";
import { useState } from 'react';

function AnimatedBox() {
  const [isHovered, setIsHovered] = useState(false);

  return (
    <motion.div
      style={{
        width: '100px',
        height: '100px',
        backgroundColor: isHovered ? '#ff0088' : '#0099ff',
        borderRadius: '10px',
        display: 'flex',
        justifyContent: 'center',
        alignItems: 'center',
        color: 'white',
        cursor: 'pointer'
      }}
      initial={{ x: 0, scale: 1 }}
      animate={{ x: isHovered ? 50 : 0, scale: isHovered ? 1.1 : 1 }}
      transition={{ type: "spring", stiffness: 300, damping: 20 }}
      onHoverStart={() => setIsHovered(true)}
      onHoverEnd={() => setIsHovered(false)}
    >
      Hover Me
    </motion.div>
  );
}

// Example of how you would render this component in a client-side React application:
// import ReactDOM from 'react-dom/client';
// const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
// root.render(<AnimatedBox />);

view raw JSON →