@aarsteinmedia/dotlottie-player-light

中文文档
6.0.0发布于 2025/06/22GPL-2.0-or-laterTypeScriptES Module近 30 天下载 3402

⛔️ DEPRECATED. Use @aarsteinmedia/dotlottie-player/light instead.

此软件包已被标记为弃用

Package is deprecated. Use @aarsteinmedia/dotlottie-player/light instead.

原始使用文档
文档目录13 节
  1. Installation
  2. In HTML
  3. In JavaScript or TypeScript
  4. Usage
  5. Control playback of multiple animations in a single file
  6. Angular
  7. React.js / Next.js
  8. Vue.js / Nuxt.js (using Vite.js)
  9. Properties
  10. Methods
  11. Events
  12. WordPress Plugins
  13. License

DEPRECATED

No Maintenance Intended Awesome Vector Animations

The functionality of this package has been moved inside @aarsteinmedia/dotlottie-player. To use light version, import @aarsteinmedia/dotlottie-player/light. This package will no longer recieve any updates.

This is a light version of of @aarsteinmedia/dotlottie-player. If you only need SVG renderer (not HTML or Canvas) and don't need to convert JSON to dotLottie or combine animations on the fly, this one is for you. This version supports dotLottie format as well as JSON, and you can toggle between multiple animations in a single file.

The component is compatible with server side rendering, and like any good web component it's framework agnostic.

Installation

In HTML

  • Import from CDN:
<script src="https://unpkg.com/@aarsteinmedia/dotlottie-player-light@latest/dist/index.js"></script>
  • Import from node_modules directory:
<script src="/node_modules/@aarsteinmedia/dotlottie-player-light/dist/index.js"></script>

In JavaScript or TypeScript

  1. Install using npm or yarn:
npm install --save @aarsteinmedia/dotlottie-player-light
  1. Import in your app:
import '@aarsteinmedia/dotlottie-player-light'

Usage

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

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

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

const lottiePlayer = document.querySelector('dotlottie-player')
lottiePlayer.load('https://storage.googleapis.com/aarsteinmedia/am.lottie')

Control playback of multiple animations in a single file

Use the full version of this package to combine multiple animations into one file. To control the playback you can either use the next() and prev() methods, the navigation buttons in the controls or the parameter multiAnimationSettings in the markup.

In the example below the first animation will play once, and then the next animation will loop:

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

Angular

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

@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

If you've already imported the library in a parent component, you don't need to import it again in children of that component. If you want to assign the element a CSS class note that you need to use the class namespace, and not className.

import '@aarsteinmedia/dotlottie-player-light'

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

export default App

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

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

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

export default App

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

Compared to React and Angular there's a couple of extra steps, but surely nothing too daunting.

  1. Declare the dotlottie-player tag as a custom element, to prevent Vue from attempting to resolve it.

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) => ['dotlottie-player'].includes(tag),
        }
      }
    })
  ]
})

In Nuxt.js

nuxt.config.ts:

export default defineNuxtConfig({
  vue: {
    compilerOptions: {
      isCustomElement: (tag: string) => ['dotlottie-player'].includes(tag),
    }
  }
})
  1. Import/initiate the component.

In Vue.js

main.ts:

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

const app = createApp(App)
app.component('DotLottiePlayer', DotLottiePlayer)

In Nuxt.js

Create a plugins folder in your root if it doesn't exist already, add a file named dotlottie-player-light.js:

import DotLottiePlayer from '@aarsteinmedia/dotlottie-player-light'

export default defineNuxtPlugin(({ vueApp }) => {
  vueApp.component('DotLottiePlayer', DotLottiePlayer)
})
  1. The component can now be used in your pages or components template tags.
<template>
  <dotlottie-player
    src="https://storage.googleapis.com/aarsteinmedia/am.lottie"
    autoplay
    controls
    subframe
    loop
    style="width: 320px; margin: auto;"
  />
</template>

Properties

Property / AttributeDescriptionTypeDefault
autoplayPlay animation on loadbooleanfalse
backgroundBackground colorstringundefined
controlsShow controlsbooleanfalse
countNumber of times to loop animationnumberundefined
directionDirection of animation1 | -11
hoverWhether to play on mouse hoverbooleanfalse
loopWhether to loop animationbooleanfalse
modePlay modenormal | bouncenormal
objectfitResizing of animation in containercontain | cover | fill | nonecontain
speedAnimation speednumber1
src (required)URL to LottieJSON or dotLottiestringundefined
subframeWhen enabled this can help to reduce flicker on some animations, especially on Safari and iOS devices.booleanfalse

Methods

MethodFunction
destroy() => voidNullify animation and remove element from the DOM.
getLottie() => AnimationItem | nullReturns the lottie-web instance used in the component
load(src: string) => voidLoad animation by URL or JSON object
next() => voidNext animation (if several in file)
pause() => voidPause
prev() => voidPrevious animation (if several in file)
play() => voidPlay
reload() => voidReload
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
setLooping(value: boolean) => voidSet Looping
setMultiAnimationSettings(value: AnimationSettings[]) => voidSet Multi-animation settings
setSegment(value: AnimationSegment) => 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() => stringSnapshot the current frame as SVG. Triggers a download in the browser.
stop() => voidStop
toggleBoomerang() => voidToggle between bounce and normal
toggleLooping() => 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
playAnimation has started playing
pauseAnimation has paused
readyAnimation is loaded and player is ready
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 for WordPress. 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 for WordPress. 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-light 共发布 120 个版本,首次发布于 2023/09/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
6.0.0latest2025/06/221.4 年前
5.3.02025/06/211.4 年前
5.2.292025/06/161.4 年前
5.2.282025/06/111.4 年前
5.2.272025/06/111.4 年前
5.2.262025/06/091.4 年前

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

@aarsteinmedia/dotlottie-player-light 是什么?

⛔️ DEPRECATED. Use @aarsteinmedia/dotlottie-player/light instead.注意:该包已被作者标记为弃用——Package is deprecated. Use @aarsteinmedia/dotlottie-player/light instead.

如何安装 @aarsteinmedia/dotlottie-player-light?

在项目目录运行 npm install @aarsteinmedia/dotlottie-player-light,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@types/react(>= 16.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aarsteinmedia/dotlottie-player-light 支持 TypeScript 吗?

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

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

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

@aarsteinmedia/dotlottie-player-light 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 12.17.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

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

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

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

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

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

最新版本 6.0.0 发布于 2025/06/22(1.4 年前);至今共发布 120 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/09/17。作者已将其标记为弃用,新项目建议寻找替代方案。