Top Related Projects
Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/
Lottie viewer/player as an easy to use web component! https://lottiefiles.com/web-player
A lightweight magic-move library for configurable layout transitions
Quick Overview
Vue-lottie is a Vue.js wrapper for Airbnb's Lottie, a library that renders After Effects animations in real-time. It allows developers to easily integrate high-quality animations into their Vue applications, providing a seamless way to add engaging visual elements to web projects.
Pros
- Easy integration with Vue.js projects
- Supports high-quality, scalable animations
- Lightweight and performant
- Customizable playback controls
Cons
- Requires knowledge of After Effects for creating custom animations
- Limited to animations exported from After Effects
- May increase initial load time for complex animations
- Documentation could be more comprehensive
Code Examples
- Basic usage:
<template>
<lottie :options="lottieOptions" :height="200" :width="200" />
</template>
<script>
import Lottie from 'vue-lottie'
import animationData from './path/to/animation.json'
export default {
components: {
Lottie
},
data() {
return {
lottieOptions: {
animationData: animationData
}
}
}
}
</script>
- Controlling animation playback:
<template>
<div>
<lottie :options="lottieOptions" :height="200" :width="200" @animCreated="handleAnimation" />
<button @click="play">Play</button>
<button @click="pause">Pause</button>
<button @click="stop">Stop</button>
</div>
</template>
<script>
import Lottie from 'vue-lottie'
import animationData from './path/to/animation.json'
export default {
components: {
Lottie
},
data() {
return {
lottieOptions: {
animationData: animationData
},
anim: null
}
},
methods: {
handleAnimation(anim) {
this.anim = anim
},
play() {
if (this.anim) this.anim.play()
},
pause() {
if (this.anim) this.anim.pause()
},
stop() {
if (this.anim) this.anim.stop()
}
}
}
</script>
- Dynamically changing animation:
<template>
<lottie :options="lottieOptions" :height="200" :width="200" />
</template>
<script>
import Lottie from 'vue-lottie'
import animation1 from './path/to/animation1.json'
import animation2 from './path/to/animation2.json'
export default {
components: {
Lottie
},
data() {
return {
lottieOptions: {
animationData: animation1
}
}
},
methods: {
changeAnimation() {
this.lottieOptions = {
...this.lottieOptions,
animationData: animation2
}
}
}
}
</script>
Getting Started
-
Install the package:
npm install vue-lottie
-
Import and use in your Vue component:
<template> <lottie :options="lottieOptions" :height="200" :width="200" /> </template> <script> import Lottie from 'vue-lottie' import animationData from './path/to/animation.json' export default { components: { Lottie }, data() { return { lottieOptions: { animationData: animationData } } } } </script>
-
Ensure you have an animation JSON file exported from After Effects using the Bodymovin plugin.
Competitor Comparisons
Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/
Pros of lottie-web
- More comprehensive and feature-rich, supporting a wider range of animation capabilities
- Platform-agnostic, can be used with various frameworks or vanilla JavaScript
- Larger community and more frequent updates
Cons of lottie-web
- Steeper learning curve due to more complex API
- Larger file size, which may impact performance for simpler animations
- Requires more setup and configuration for use in Vue.js projects
Code Comparison
vue-lottie:
<template>
<lottie :options="lottieOptions" :height="400" :width="400" />
</template>
<script>
import Lottie from 'vue-lottie'
import animationData from './animation.json'
export default {
components: { Lottie },
data() {
return {
lottieOptions: { animationData }
}
}
}
</script>
lottie-web:
import lottie from 'lottie-web'
import animationData from './animation.json'
const container = document.getElementById('lottie-container')
const anim = lottie.loadAnimation({
container: container,
renderer: 'svg',
loop: true,
autoplay: true,
animationData: animationData
})
The vue-lottie example shows a more Vue-specific implementation, while lottie-web demonstrates a vanilla JavaScript approach. vue-lottie simplifies the integration process for Vue.js projects, whereas lottie-web offers more flexibility but requires additional setup for framework-specific use.
Lottie viewer/player as an easy to use web component! https://lottiefiles.com/web-player
Pros of lottie-player
- Framework-agnostic: Can be used with any JavaScript framework or vanilla JS
- More actively maintained with frequent updates
- Supports a wider range of Lottie features and animations
Cons of lottie-player
- Larger file size and potentially higher performance overhead
- May require additional setup for Vue.js integration
Code Comparison
vue-lottie:
<lottie
:options="lottieOptions"
:height="400"
:width="400"
v-on:animCreated="handleAnimation"
/>
lottie-player:
<lottie-player
src="https://assets5.lottiefiles.com/packages/lf20_UJNc2t.json"
background="transparent"
speed="1"
style="width: 300px; height: 300px;"
loop
autoplay
></lottie-player>
Summary
lottie-player offers greater flexibility and broader support for Lottie animations, making it suitable for various projects. However, vue-lottie provides a more streamlined integration for Vue.js applications. The choice between the two depends on the specific project requirements, with lottie-player being more versatile but potentially requiring additional setup for Vue.js projects.
A lightweight magic-move library for configurable layout transitions
Pros of react-flip-toolkit
- More comprehensive animation toolkit for React applications
- Supports complex FLIP animations and transitions
- Offers fine-grained control over animation timing and easing
Cons of react-flip-toolkit
- Steeper learning curve due to more advanced features
- Potentially higher performance overhead for complex animations
- Limited to React ecosystem, unlike vue-lottie's adaptability
Code Comparison
react-flip-toolkit:
import { Flipper, Flipped } from 'react-flip-toolkit'
<Flipper flipKey={someKey}>
<Flipped flipId="uniqueId">
<div>Animated content</div>
</Flipped>
</Flipper>
vue-lottie:
<template>
<lottie :options="lottieOptions" :height="400" :width="400" />
</template>
<script>
import lottie from 'vue-lottie'
import animationData from './animation.json'
export default {
components: { lottie },
data() {
return { lottieOptions: { animationData } }
}
}
</script>
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
Lottie Animation View for Vue (React, Angular)
Generated by create-vue-component
Wapper of bodymovin.js
bodymovin is Adobe After Effects plugin for exporting animations as JSON, also it provide bodymovin.js for vender them as svg/canvas/html.
Demo
https://chenqingspring.github.io/vue-lottie
Why Lottie?
Flexible After Effects features
We currently support solids, shape layers, masks, alpha mattes, trim paths, and dash patterns. And weâll be adding new features on a regular basis.
Manipulate your animation any way you like
You can go forward, backward, and most importantly you can program your animation to respond to any interaction.
Small file sizes
Bundle vector animations within your app without having to worry about multiple dimensions or large file sizes. Alternatively, you can decouple animation files from your appâs code entirely by loading them from a JSON API.
Learn more ⺠http://airbnb.design/lottie/
Looking for lottie files ⺠https://www.lottiefiles.com/
Installation
Install through npm:
npm install --save vue-lottie
Usage
<template>
<div id="app">
<lottie :options="defaultOptions" :height="400" :width="400" v-on:animCreated="handleAnimation"/>
<div>
<p>Speed: x{{animationSpeed}}</p>
<input type="range" value="1" min="0" max="3" step="0.5"
v-on:change="onSpeedChange" v-model="animationSpeed">
</div>
<button v-on:click="stop">stop</button>
<button v-on:click="pause">pause</button>
<button v-on:click="play">play</button>
</div>
</template>
<script>
import Lottie from './lottie.vue';
import * as animationData from './assets/pinjump.json';
export default {
name: 'app',
components: {
'lottie': Lottie
},
data() {
return {
defaultOptions: {animationData: animationData},
animationSpeed: 1
}
},
methods: {
handleAnimation: function (anim) {
this.anim = anim;
},
stop: function () {
this.anim.stop();
},
play: function () {
this.anim.play();
},
pause: function () {
this.anim.pause();
},
onSpeedChange: function () {
this.anim.setSpeed(this.animationSpeed);
}
}
}
</script>
Configuration
You can pass a configuration object through options
property:
- animationData: an Object with the exported animation data.
- path: the relative path to the animation object. (animationData and path are mutually exclusive)
- loop: true / false / number
- autoplay: true / false it will start playing as soon as it is ready
- name: animation name for future reference
- renderer: 'svg' / 'canvas' / 'html' to set the renderer
- container: the dom element on which to render the animation
More information on Bodymoving Documentation
Related Projects
- Bodymovin vue-lottie is a wrapper of bodymovin
- Angular Lottie angular implementation
- React Lottie react implementation
- React Native Lottie react native implementation by airbnb
- IOS Lottie ios implementation by airbnb
- Android Lottie android implementation by airbnb
Contribution
Your contributions and suggestions are heartily welcome.
License
MIT
Top Related Projects
Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/
Lottie viewer/player as an easy to use web component! https://lottiefiles.com/web-player
A lightweight magic-move library for configurable layout transitions
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