Convert Figma logo to code with AI

vueuse logomotion

🤹 Vue Composables putting your components in motion

2,422
83
2,422
44

Top Related Projects

26,342

A modern animation library for React and JavaScript

A zero-config, drop-in animation utility that adds smooth transitions to your web app. You can use it with React, Vue, or any other JavaScript application.

50,532

JavaScript animation engine

20,011

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

Javascript library to create physics-based animations

Quick Overview

VueUse Motion is a Vue Composable for smooth animations and transitions. It provides a simple API to create powerful animations in Vue applications, leveraging the power of the Web Animations API and CSS transitions.

Pros

  • Easy to use with a declarative API
  • Supports both Vue 2 and Vue 3
  • Lightweight and performant
  • Integrates well with existing Vue projects

Cons

  • Limited documentation for advanced use cases
  • May require additional setup for complex animations
  • Learning curve for developers new to animation concepts
  • Some features might not be supported in older browsers

Code Examples

  1. Basic animation:
<template>
  <div v-motion="{ opacity: 1, y: 0 }" :initial="{ opacity: 0, y: 100 }">
    Fade in and slide up
  </div>
</template>
  1. Chained animations:
<template>
  <div
    v-motion
    :initial="{ scale: 0, rotate: 0 }"
    :enter="{ scale: 1, rotate: 360, transition: { duration: 1000, type: 'spring' } }"
  >
    Scale and rotate
  </div>
</template>
  1. Scroll-triggered animation:
<template>
  <div
    v-motion
    :initial="{ opacity: 0, y: 100 }"
    :visible="{ opacity: 1, y: 0, transition: { delay: 300 } }"
  >
    Animate on scroll
  </div>
</template>

Getting Started

  1. Install the package:
npm install @vueuse/motion
  1. Import and use in your Vue component:
<script setup>
import { useMotion } from '@vueuse/motion'

const target = ref(null)
const motionInstance = useMotion(target, {
  initial: { opacity: 0, y: 100 },
  enter: { opacity: 1, y: 0 },
})
</script>

<template>
  <div ref="target">Animated content</div>
</template>

This setup creates a simple fade-in and slide-up animation for the div element when it enters the viewport.

Competitor Comparisons

26,342

A modern animation library for React and JavaScript

Pros of Motion

  • Supports React, Vue, Solid, and Svelte frameworks
  • Offers a more comprehensive animation API with features like gestures and scroll-based animations
  • Provides a declarative syntax for complex animations

Cons of Motion

  • Larger bundle size due to cross-framework support
  • Steeper learning curve for beginners
  • May have performance overhead in simpler use cases

Code Comparison

Motion:

<motion.div
  initial={{ opacity: 0, scale: 0.5 }}
  animate={{ opacity: 1, scale: 1 }}
  transition={{ duration: 0.5 }}
>
  Hello World
</motion.div>

VueUse/motion:

<template>
  <div v-motion="{ initial: { opacity: 0, scale: 0.5 }, enter: { opacity: 1, scale: 1 } }">
    Hello World
  </div>
</template>

Summary

Motion offers a more versatile solution for animations across multiple frameworks, with advanced features like gesture and scroll-based animations. However, this comes at the cost of a larger bundle size and potentially more complex setup. VueUse/motion, being Vue-specific, provides a simpler API and lighter weight solution for basic animations in Vue applications. The choice between the two depends on the specific project requirements, target framework(s), and the complexity of animations needed.

A zero-config, drop-in animation utility that adds smooth transitions to your web app. You can use it with React, Vue, or any other JavaScript application.

Pros of Auto-animate

  • Simpler API with automatic animation detection
  • Framework-agnostic, works with vanilla JavaScript and various frameworks
  • Smaller bundle size and lighter performance impact

Cons of Auto-animate

  • Less fine-grained control over animations
  • Limited to a set of predefined animations
  • Lacks advanced features like gesture-based animations

Code Comparison

Motion:

import { useMotion } from '@vueuse/motion'

const el = useMotion(target, {
  initial: { opacity: 0, y: 100 },
  enter: { opacity: 1, y: 0 },
})

Auto-animate:

import { autoAnimate } from '@formkit/auto-animate'

onMounted(() => {
  autoAnimate(parentElement)
})

Motion offers more detailed control over animations, allowing developers to specify initial and final states. Auto-animate simplifies the process by automatically detecting and animating changes to the DOM.

Motion provides a rich set of features for complex animations, including gesture support and advanced timing functions. Auto-animate focuses on simplicity and ease of use, making it ideal for quick implementations of basic animations across different frameworks.

While Motion is specifically designed for Vue.js, Auto-animate's framework-agnostic approach makes it more versatile for projects using multiple or alternative frameworks.

50,532

JavaScript animation engine

Pros of Anime

  • Lightweight and versatile, with a small file size
  • Supports a wide range of animation types, including SVG animations
  • Can be used with or without JavaScript frameworks

Cons of Anime

  • Lacks Vue-specific integrations and optimizations
  • May require more manual setup and configuration for complex animations
  • Not specifically designed for Vue's reactivity system

Code Comparison

Motion:

<template>
  <div v-motion :initial="{ opacity: 0 }" :enter="{ opacity: 1 }">
    Animated content
  </div>
</template>

Anime:

anime({
  targets: '.element',
  opacity: [0, 1],
  duration: 1000,
  easing: 'easeInOutQuad'
});

Summary

Motion is tailored for Vue applications, offering seamless integration with Vue's reactivity system and component-based architecture. It provides a more declarative approach to animations within Vue components.

Anime, on the other hand, is a more general-purpose animation library that can be used across various JavaScript environments. It offers greater flexibility but may require more setup when used in Vue projects.

The choice between the two depends on the specific needs of your project and your preference for Vue-specific tooling versus a more versatile animation library.

20,011

GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web

Pros of GSAP

  • More comprehensive animation capabilities, including complex timelines and advanced easing
  • Broader browser support, including older versions
  • Larger ecosystem with plugins for specific animation needs

Cons of GSAP

  • Steeper learning curve due to its extensive feature set
  • Larger file size, which may impact page load times
  • Requires a license for commercial use in some scenarios

Code Comparison

VueUse Motion:

const el = ref(null)
const { x, y } = useMouseInElement(el)

const motionInstance = useMotion(el, {
  initial: { opacity: 0, y: 100 },
  enter: { opacity: 1, y: 0 },
})

GSAP:

gsap.to(".box", {
  duration: 1,
  x: 100,
  y: 50,
  rotation: 360,
  ease: "elastic.out(1, 0.3)",
})

Summary

VueUse Motion is a lightweight, Vue-specific animation library, while GSAP is a more powerful, framework-agnostic animation toolkit. VueUse Motion offers simpler integration with Vue projects and a smaller footprint, whereas GSAP provides more advanced animation capabilities at the cost of a larger file size and steeper learning curve.

Javascript library to create physics-based animations

Pros of dynamics.js

  • Lightweight and standalone, with no dependencies
  • Works with any JavaScript framework or vanilla JS
  • Provides a wide range of easing functions and spring animations

Cons of dynamics.js

  • Less integration with modern reactive frameworks like Vue
  • Not actively maintained (last update in 2015)
  • Limited to DOM manipulation and CSS properties

Code Comparison

dynamics.js:

dynamics.animate(element, {
  translateX: 100,
  scale: 2
}, {
  type: dynamics.spring,
  duration: 1000
})

motion:

import { useMotion } from '@vueuse/motion'

const el = useMotion(elementRef, {
  initial: { x: 0, scale: 1 },
  enter: { x: 100, scale: 2 },
})

Key Differences

  • motion is specifically designed for Vue.js, offering seamless integration with Vue components and reactivity system
  • dynamics.js provides more low-level control over animations, while motion offers a higher-level abstraction
  • motion supports Vue 3's Composition API, making it more suitable for modern Vue applications
  • dynamics.js has a larger community and more historical usage, but motion is more actively maintained and aligned with current web development practices

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

🤹 @vueuse/motion

npm npm npm Netlify Status

Vue Composables putting your components in motion

  • 🏎 Smooth animations based on Popmotion
  • 🎮 Declarative API inspired by Framer Motion
  • 🚀 Plug & play with 20+ presets
  • 🌐 SSR Ready
  • 🚚 First-class support for Nuxt 3
  • ✨ Written in TypeScript
  • 🏋️‍♀️ Lightweight with <20kb bundle size

🌍 Documentation

👀 Demos

Quick Start

Let's get started by installing the package and adding the plugin.

From your terminal:

npm install @vueuse/motion

In your Vue app entry file:

import { createApp } from 'vue'
import { MotionPlugin } from '@vueuse/motion'
import App from './App.vue'

const app = createApp(App)

app.use(MotionPlugin)

app.mount('#app')

You can now animate any of your component, HTML or SVG elements using v-motion.

<template>
  <div
    v-motion
    :initial="{
      opacity: 0,
      y: 100,
    }"
    :enter="{
      opacity: 1,
      y: 0,
    }"
  />
</template>

To see more about how to use directives, check out Directive Usage.

To see more about what properties you can animate, check out Motion Properties.

To see more about how to create your own animation styles, check out Transition Properties.

To see more about what are variants and how you can use them, check out Variants.

To see more about how to control your declared variants, check out Motion Instance.

Nightly release channel

You can try out the latest changes before a stable release by installing the nightly release channel.

npm install @vueuse/motion@npm:vueuse-motion-nightly

Credits

This package is heavily inspired by Framer Motion by @mattgperry.

If you are interested in using WAAPI, check out Motion.dev!

I would also like to thank antfu, patak-dev and kazupon for their kind help!

If you like this package, consider following me on GitHub and on Twitter.

👋

NPM DownloadsLast 30 Days