Skip to content

v-lottie

Lottie animation player.

Since: 1.5.0

Usage

With URL

vue
<template>
  <div v-lottie="'https://assets.example.com/animation.json'"></div>
</template>

With Animation Data

vue
<template>
  <div v-lottie="animationData"></div>
</template>

<script setup>
import animationData from './animation.json'
</script>

With Options

vue
<template>
  <div v-lottie="{
    animationData: animationData,
    autoplay: true,
    loop: true,
    speed: 1.5,
    onComplete: () => console.log('Done')
  }"></div>
</template>

API

Options

OptionTypeDefaultDescription
animationDataobject-Lottie animation data object
pathstring-URL to animation JSON
autoplaybooleantrueAuto play on load
loopboolean | numbertrueLoop animation
speednumber1Playback speed
direction1 | -11Playback direction
onComplete() => void-Callback when animation completes
onLoopComplete() => void-Callback when loop completes
onEnterFrame(frame: number) => void-Callback on each frame

Examples

Controlled Animation

vue
<template>
  <div v-lottie="{
    animationData: animationData,
    autoplay: false,
    loop: false
  }" ref="lottieRef">
  </div>
  <button @click="play">Play</button>
  <button @click="pause">Pause</button>
  <button @click="stop">Stop</button>
</template>

Interactive Speed Control

vue
<template>
  <div v-lottie="{ animationData: data, speed: speed }"></div>
  <input v-model.number="speed" type="range" min="0.5" max="3" step="0.1" />
</template>

Composable API

For programmatic use, you can use the useLottie composable:

typescript
import { useLottie } from 'directix'

const { play, pause, stop, setSpeed, setDirection, goToAndStop, goToAndPlay } = useLottie({
  animationData,
  autoplay: true,
  loop: true
})

// Control playback
play()
pause()
stop()

// Set speed (0.5x to 3x)
setSpeed(1.5)

// Set direction (1 = forward, -1 = backward)
setDirection(-1)

// Go to specific frame
goToAndStop(50)
goToAndPlay(50, true)

UseLottieReturn

PropertyTypeDescription
play() => voidPlay animation
pause() => voidPause animation
stop() => voidStop and reset animation
setSpeed(speed: number) => voidSet playback speed
setDirection(direction: 1 | -1) => voidSet playback direction
goToAndStop(frame: number, isFrame?: boolean) => voidGo to frame and stop
goToAndPlay(frame: number, isFrame?: boolean) => voidGo to frame and play

Code Generator

Quick Code Generator
<template>
  <div v-lottie>
    <!-- Lottie animation player. directive -->
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

// Configure your options here
const options = {}
</script>

Released under the MIT License.