@aarsteinmedia/dotlottie-player

中文文档
6.6.8发布于 2026/11/03GPL-2.0-or-laterTypeScriptES Module近 30 天下载 1.8万

Web Component for playing Lottie animations in your web app.

原始使用文档
文档目录18 节
  1. Choosing a build
  2. Demo
  3. Installation
  4. In HTML
  5. In JavaScript or TypeScript
  6. Usage
  7. Load animation
  8. Convert to dotLottie
  9. Convert to JSON
  10. Combine animations
  11. Angular
  12. React.js / Next.js
  13. Vue.js / Nuxt.js (using Vite.js)
  14. Properties
  15. Methods
  16. Events
  17. WordPress Plugins
  18. License

AM LottiePlayer

Awesome Vector Animations

We proudly claim this to be the most versatile, lightweight, and efficient Lottie Player Web Component available. It's compatible with server-side rendering and completely framework-agnostic.

Choosing a build

ImportWhen to use it
@aarsteinmedia/dotlottie-playerFull player: all renderers, expressions, SVG effects, plus convert/combine on the fly.
@aarsteinmedia/dotlottie-player/svgSVG renderer with expressions and SVG effects, but without convert/combine. Use this when you need those features but don’t want to load the full build.
@aarsteinmedia/dotlottie-player/canvasCanvas renderer – usually easier on the hardware and visually similar to SVG for most animations. Most SVG-specific effects aren’t available, and animation support isn’t as broad as SVG.
@aarsteinmedia/dotlottie-player/lightSmallest build: SVG only, with expressions and SVG effects stripped out. No convert/combine.

Demo

Here is a demo, running on Next.js with TypeScript.

Installation

In HTML

  • Import from CDN:

    • Full:
      <script src="https://unpkg.com/@aarsteinmedia/dotlottie-player@latest/dist/unpkg-full.js"></script>
      
    • SVG:
      <script src="https://unpkg.com/@aarsteinmedia/dotlottie-player@latest/dist/unpkg-svg.js"></script>
      
    • Canvas:
      <script src="https://unpkg.com/@aarsteinmedia/dotlottie-player@latest/dist/unpkg-canvas.js"></script>
      
    • Light:
      <script src="https://unpkg.com/@aarsteinmedia/dotlottie-player@latest/dist/unpkg-light.js"></script>
      
  • Import from node_modules the same way, e.g. /node_modules/@aarsteinmedia/dotlottie-player/dist/unpkg-full.js.

In JavaScript or TypeScript

  1. Install using npm, pnpm, or yarn:

    pnpm add @aarsteinmedia/dotlottie-player
    
  2. Import in your app (pick one build):

    import '@aarsteinmedia/dotlottie-player'
    // or:
    import '@aarsteinmedia/dotlottie-player/svg'
    import '@aarsteinmedia/dotlottie-player/canvas'
    import '@aarsteinmedia/dotlottie-player/light'
    

Because this is a Web Component, you're adding it to the global scope of your web app. Unlike modular components, it should only be imported once – preferably early in your app lifecycle.

If you're using TypeScript and want to import the component type, do it modular in addition to the global import:

import '@aarsteinmedia/dotlottie-player' // Do this once globally.
import type DotLottiePlayer from '@aarsteinmedia/dotlottie-player' // Do this per file that needs the type.

⚠️ Note that this pattern may provoke linter errors, such as import/no-duplicates.

Usage

Add the dotlottie-player element to your markup and point the src to a Lottie animation of your choice:

<dotlottie-player
  autoplay
  controls
  subframe
  loop
  id="find-me"
  src="https://storage.googleapis.com/aarsteinmedia/am.lottie"
  style="width: 320px; margin: auto;"
>
</dotlottie-player>

Load animation

To set animations programmatically, use the load() method.

const player = document.querySelector('#find-me')
await player?.load('https://storage.googleapis.com/aarsteinmedia/am.lottie')

Convert to dotLottie

(Full build only.)

If you have a Lottie JSON animation and want to convert it to a dotLottie file – to leverage compression, combine multiple animations, and maintain a tidy file library – you can use the convert() method. This will trigger a browser download.

If controls are visible, there’s also a convert button in the context menu on the right-hand side.

Convert to JSON

(Full build only.)

If you're debugging a dotLottie animation (e.g., expressions aren’t working as expected), you can convert it to JSON either using the convert() method or via the convert button if controls are enabled.

Combine animations

(Full build only.)

To combine multiple animations into a single dotLottie file, use the addAnimation() method. This also triggers a browser download. Source files can be either dotLottie or JSON, and the output will always be dotLottie:

const player = document.querySelector('#find-me')
await player?.addAnimation([
  { id: 'animation_1', url: '/url/to/animation_1.lottie' },
  { id: 'animation_2', url: '/url/to/animation_2.json', direction: -1, speed: 2 }
])

You can also use this method without any <dotlottie-player> on the page. As long as the script is loaded, dotLottiePlayer() is available as a global method.

await dotLottiePlayer().addAnimation([
  { id: 'animation_1', url: '/path/to/animation_1.lottie' },
  { id: 'animation_2', url: '/path/to/animation_2.json', direction: -1, speed: 2 }
])

The new file will automatically load the first animation when initialized. You can toggle between animations using the next() and prev() methods, or the navigation buttons in the controls.

Here’s how to control playback settings for multiple animations:

<dotlottie-player
  subframe
  id="find-me"
  src="/path/to/combined-animations.lottie"
>
</dotlottie-player>
const player = document.querySelector('#find-me')
player?.setMultiAnimationSettings([
  {
    autoplay: true
  },
  {
    autoplay: true,
    loop: true
  }
])

Angular

  1. Import the component in app.component.ts.
import { Component } from '@angular/core'
import '@aarsteinmedia/dotlottie-player'

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'your-app-name'
}
  1. Add the player to your HTML template.

React.js / Next.js

Because this is a Web Component and not a React component, note that you must use the class attribute (not className) when assigning a CSS class.

If you prefer pure React logic, you may want to check out @aarsteinmedia/dotlottie-react.

import '@aarsteinmedia/dotlottie-player'

function App() {
  return (
    <dotlottie-player
      autoplay
      controls
      loop
      class="your-class-name"
      src="https://storage.googleapis.com/aarsteinmedia/am.lottie"
      style={{
        width: '320px',
        margin: 'auto'
      }}
    />
  )
}

export default App

If you're using TypeScript and want to assign a ref, do it like this:

import { useRef } from 'react'
import '@aarsteinmedia/dotlottie-player'
import type DotLottiePlayer from '@aarsteinmedia/dotlottie-player'

function App() {
  const animation = useRef<DotLottiePlayer | null>(null)
  return (
    <dotlottie-player
      subframe
      ref={animation}
      src="https://storage.googleapis.com/aarsteinmedia/am.lottie"
    />
  )
}

export default App

Vue.js / Nuxt.js (using Vite.js)

  1. Declare the dotlottie-player tag as a custom element, so Vue doesn’t try to resolve it as a Vue component.

In Vue.js

vite.config.ts:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag: string) => tag === 'dotlottie-player',
        }
      }
    })
  ]
})

In Nuxt.js

nuxt.config.ts:

export default defineNuxtConfig({
  vue: {
    compilerOptions: {
      isCustomElement: (tag: string) => tag === 'dotlottie-player',
    }
  }
})
  1. Import the package once for its side effect (registers the custom element).

In Vue.js

main.ts:

import { createApp } from 'vue'
import '@aarsteinmedia/dotlottie-player'
import App from './App.vue'

createApp(App).mount('#app')

In Nuxt.js

Create a plugins folder in your root if it doesn't exist already, and add a client plugin named e.g. dotlottie-player.client.ts:

import '@aarsteinmedia/dotlottie-player'

export default defineNuxtPlugin(() => {})
  1. Use the element in your templates:
<template>
  <dotlottie-player
    src="https://storage.googleapis.com/aarsteinmedia/am.lottie"
    autoplay
    controls
    subframe
    loop
    style="width: 320px; margin: auto;"
  />
</template>

Properties

Property / AttributeDescriptionTypeDefault
animateOnScrollAnimate by scrolling.booleanfalse
autoplayPlay animation on load.booleanfalse
backgroundBackground color.stringtransparent
controlsShow controls.booleanfalse
countNumber of times to loop animation.number0
delayDelay playback on playOnVisible, in milliseconds.number0
descriptionDescription for screen readers.stringundefined
directionDirection of animation.1 | -11
dontFreezeOnBlurDisable freezing playback when the window loses focus (freeze-on-blur is the default).booleanfalse
hoverWhether to play on mouse hover.booleanfalse
intermissionPause between loop iterations, in milliseconds.number0
loopWhether to loop animation.booleanfalse
modePlay mode.normal | bouncenormal
mouseoutAction on mouseout.void | stop | pause | reversestop
objectfitResizing of animation in container.contain | cover | fill | none | scale-downcontain
onceWhether, if playOnVisible is true, to play once or anytime the animation is in view.booleanfalse
playOnClickWhether to toggle play on click.booleanfalse
playOnVisiblePlay when visible.booleanfalse
quietSuppress the graphic error screen on critical load errors.booleanfalse
rendererRenderer to use (full build only; other builds lock this).svg | canvas | htmlsvg
selectorPlay on clicked element by id attribute.stringundefined
simpleHide advanced controls (loop, boomerang, convert, snapshot, settings).booleanfalse
speedAnimation speed.number1
src (required)URL to Lottie JSON or dotLottie.stringundefined
subframeWhen enabled this can help to reduce flicker on some animations, especially on Safari and iOS devices.booleanfalse

Methods

MethodFunction
addAnimation(params: AddAnimationParams) => Promise<Result>(Full build only.) Combine animations into a new dotLottie file and trigger a download.
convert(params: ConvertParams) => Promise<Result>(Full build only.) Convert between JSON and dotLottie. Triggers a download in the browser.
destroy() => voidNullify animation and remove element from the DOM.
getLottie() => AnimationItem | nullReturns the lottie-web instance used in the component.
getManifest() => LottieManifest | undefinedReturns the dotLottie manifest, if any.
getMultiAnimationSettings() => AnimationSettings[]Returns multi-animation settings.
getSegment() => [number, number] | undefinedReturns the current playback segment.
load(src: string) => Promise<void>Load animation by URL or JSON string.
next() => voidNext animation (if several in file).
pause() => voidPause.
prev() => voidPrevious animation (if several in file).
play() => voidPlay.
reload() => Promise<void>Reload.
seek(value: number | string) => voidGo to frame. Can be a number or a percentage string (e.g. 50%).
setCount(value: number) => voidDynamically set number of loops.
setDirection(value: 1 | -1) => voidSet direction.
setLoop(value: boolean) => voidSet looping.
setMultiAnimationSettings(value: AnimationSettings[]) => voidSet multi-animation settings.
setSegment(value: [number, number]) => voidPlay only part of an animation. E.g. from frame 10 to frame 60 would be [10, 60].
setSpeed(value?: number) => voidSet speed.
setSubframe(value: boolean) => voidSet subframe.
snapshot(download?: boolean, name?: string) => string | nullSnapshot the current frame as SVG. Downloads by default when download is true.
stop() => voidStop.
toggleBoomerang() => voidToggle between bounce and normal.
toggleLoop() => voidToggle looping.
togglePlay() => voidToggle play.

Events

The following events are exposed and can be listened to via addEventListener calls.

NameDescription
completeAnimation is complete – including all loops
destroyedAnimation is destroyed
errorThe source cannot be parsed, fails to load, or has format errors
frameA new frame is entered
freezeAnimation is paused due to player being out of view
loadAnimation is loaded
loopA loop is completed
nextSwitched to next animation in a multi-animation file
_playAnimation has started playing
_pauseAnimation has paused
previousSwitched to previous animation in a multi-animation file
readyAnimation is loaded and player is ready
renderedPlayer UI has been rendered
stopAnimation has stopped

WordPress Plugins

We've made a free WordPress plugin that works with Gutenberg Blocks, Elementor, Divi Builder and Flatsome UX Builder: AM LottiePlayer. It has all the functionality of this package, with a helpful user interface.

It's super lightweight – and only loads on pages where animations are used.

We've also made a premium WordPress plugin for purchase: AM LottiePlayer PRO. It has an easy-to-use GUI for combining and controlling multiple Lottie animations in a single file, converting JSON to dotLottie with drag-and-drop, and many more exclusive features.

License

GPL-2.0-or-later

版本与发布记录

@aarsteinmedia/dotlottie-player 共发布 185 个版本,首次发布于 2023/09/17;过去 12 个月发布了 47 个版本。

版本发布日期距今
6.6.8latest2026/11/033 天前
6.6.72026/11/033 天前
6.6.62026/10/2412 天前
6.6.52026/10/1027 天前
6.6.42026/10/0927 天前
6.6.32026/10/0828 天前

关于 @aarsteinmedia/dotlottie-player 的常见问题

@aarsteinmedia/dotlottie-player 是什么?

Web Component for playing Lottie animations in your web app.

如何安装 @aarsteinmedia/dotlottie-player?

在项目目录运行 npm install @aarsteinmedia/dotlottie-player,或使用 pnpm add / yarn add / bun add。

@aarsteinmedia/dotlottie-player 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aarsteinmedia/dotlottie-player 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aarsteinmedia/dotlottie-player 可以商用吗?

@aarsteinmedia/dotlottie-player 使用 GPL-2.0-or-later 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以兼容的 GPL 许可开源。仅在内部使用、不对外分发时不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@aarsteinmedia/dotlottie-player 的下载量有多少?

根据 npm 官方下载统计,@aarsteinmedia/dotlottie-player 在 2026/10/05 – 2026/11/03 这 30 天内被下载 17,805 次,日均约 594 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aarsteinmedia/dotlottie-player 还在维护吗?

最新版本 6.6.8 发布于 2026/11/03(3 天前);至今共发布 185 个版本,其中过去 12 个月发布了 47 个;首次发布于 2023/09/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。