Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@lottiefiles/lottie-player

LottieFiles459kMIT2.0.12TypeScript support: included

Lottie animation and Telegram Sticker player web components.

lottie, animation, lottiefiles, web component, component, lit-element, player, telegram sticker, tgs

readme

lottie-player Web Component

This is a Web Component for easily embedding and playing Lottie animations and the Lottie-based Telegram Sticker (tgs) animations in websites.

npm webcomponents.org

Demo

screencast

Basic usage examples

Documentation

For full documentation, visit docs.lottiefiles.com/lottie-player

Installation

In HTML, import from CDN or from the local Installation:

Lottie Player:
  • Import from CDN.
<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>
  • Import from local node_modules directory.
<script src="/node_modules/@lottiefiles/lottie-player/dist/lottie-player.js"></script>
Telegram Sticker (TGS) Player:
  • Import from CDN.
<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/tgs-player.js"></script>
  • Import from local node_modules directory.
<script src="/node_modules/@lottiefiles/lottie-player/dist/tgs-player.js"></script>

In Javascript or TypeScript:

  1. Install package using npm or yarn.
npm install --save @lottiefiles/lottie-player
  1. Import package in your code.
import "@lottiefiles/lottie-player";

Usage

Lottie-Player

Add the element lottie-player and set the src property to a URL pointing to a valid Bodymovin JSON.

<lottie-player
  autoplay
  controls
  loop
  mode="normal"
  src="https://assets3.lottiefiles.com/packages/lf20_UJNc2t.json"
  style="width: 320px"
>
</lottie-player>

You may set and load animations programatically as well.

<lottie-player autoplay controls loop mode="normal" style="width: 320px">
</lottie-player>
const player = document.querySelector("lottie-player");
player.addEventListener("rendered", (e) => {
  //Load via URL
  player.load("https://assets3.lottiefiles.com/packages/lf20_UJNc2t.json");
  // or load via a Bodymovin JSON string/object
  player.load(
    '{"v":"5.3.4","fr":30,"ip":0,"op":38,"w":315,"h":600,"nm":"new", ... }'
  );
});

TGS-Player

Add the element tgs-player and set the src property to a URL pointing to a valid TGS JSON.

<tgs-player autoplay loop mode="normal" src="https//domain/example.tgs">
</tgs-player>

ReactJS & VueJS

Import the player either as

import * as LottiePlayer from "@lottiefiles/lottie-player";

or

require("@lottiefiles/lottie-player");

Use as follows

<lottie-player
  autoplay
  controls
  loop
  mode="normal"
  src="https://assets3.lottiefiles.com/packages/lf20_UJNc2t.json"
  style="width: 320px"
></lottie-player>

Typescript ReactJS

Import the player either as

import * as LottiePlayer from "@lottiefiles/lottie-player";

or

require("@lottiefiles/lottie-player");

Use as follows

<lottie-player
  autoplay
  controls
  loop
  mode="normal"
  src="https://assets3.lottiefiles.com/packages/lf20_UJNc2t.json"
  style="width: 320px"
></lottie-player>

For typescript projects an added step is required. The component must be declared as a JSX intrinsic element. Create a file 'declarations.d.ts' in the root of your project and add the code below to the file.

declare namespace JSX {
  interface IntrinsicElements {
    "lottie-player": any;
  }
}

Nuxt 2

Create a lottie-player.js file inside the /plugins folder and add the below code to the file:

import * as LottiePlayer from "@lottiefiles/lottie-player";

\ Open nuxt.config.js file and add the following entry to register the newly created plugin:

export default {
  plugins: [{ src: "~/plugins/lottie-player.js", mode: "client" }]
}

This is because the player script needs to be rendered on the browser/client side and we must configure Nuxt to load the script on the client side only.
\ You would then be able to use the player as follows inside any component:

<lottie-player
  autoplay
  controls
  loop
  style="width:400px"
  src="https://assets3.lottiefiles.com/packages/lf20_RItkEz.json"
  speed="1"
  debug
/>

Nuxt 3

The process for Nuxt 3 is slightly different.
Create a lottie-player.client.ts file inside the /plugins folder and add the below code to the file:

import * as LottiePlayer from "@lottiefiles/lottie-player";

export default defineNuxtPlugin(() => LottiePlayer);

\ Your plugin will be automatically available throughout your Nuxt application thanks to the plugin auto-registration. Note the client suffix in the name of the plugin - this tells Nuxt to load it only on the client side, as the Lottie Player script can only be rendered in the browser.

You would then be able to use the player as follows inside any component:

<lottie-player
  autoplay
  controls
  loop
  style="width:400px"
  src="https://assets3.lottiefiles.com/packages/lf20_RItkEz.json"
  speed="1"
  debug
/>

NextJS

The process to import in NextJS is similar to Nuxt in the sense that on SSR mode, the library must be declared as a client side module. To do this, import the library within a react useEffect hook.

import React, { useRef } from "react";

export default function Home() {
  const ref = useRef(null);
  React.useEffect(() => {
    import("@lottiefiles/lottie-player");
  });
  return (
    <div className={styles.container}>
      <main className={styles.main}>
        <lottie-player
          id="firstLottie"
          ref={ref}
          autoplay
          controls
          loop
          mode="normal"
          src="https://assets4.lottiefiles.com/packages/lf20_gb5bmwlm.json"
          style={{ width: "300px", height: "300px" }}
        ></lottie-player>
      </main>
    </div>
  );
}

Do add a declaration file named declaration.d.ts to the root of the project as well

declare namespace JSX {
  interface IntrinsicElements {
    "lottie-player": any;
  }
}

Full documentation on player properties, methods, events and styling for the Lottie-player are available here.

Community & Support

  • Github issues. For bugs and errors you encounter using this player.
  • Discord. For hanging out with the community and sharing your awesome Lottie animations!
Project Description
lottie-react A React component for the Lottie Web player.
lottie-vue A Vue component for the Lottie player.
svelte-lottie-player Lottie player component for use with Svelte.
jLottie jLottie is suitable as a general purpose lottie player, though implements a subset of the features in the core player - this approach leads to a tiny footprint and great performance.
lottie-interactivity This is a small library to add scrolling, cursor interactivity and interaction chaining to your Lottie Animations.
dotLottie dotLottie is an open-source file format that aggregates one or more Lottie files and their associated resources into a single file. They are ZIP archives compressed with the Deflate compression method and carry the file extension of ".lottie".
lottie-js The library consists of methods to map the Lottie JSON to the object model and interact with properties as well as manipulate them.
lottie-theming A library to extract themable properties and apply different themes to a given Lottie

License

MIT License © LottieFiles.com

changelog

Changelog

All notable changes to this project will be documented in this file. The format is based on Keep a Changelog and this project adheres to Semantic Versioning, enforced with semantic-release.

1.6.0 (2022-12-01)

Features

  • added disable check prop (860771f)

1.5.8 (2022-10-24)

Bug Fixes

  • package update: package update (f108f46)

1.5.7 (2022-04-25)

Bug Fixes

  • player: add isConnected check to disconnectedCallback (496dc8f)

1.3.1 (2022-02-22)

Bug Fixes

  • fixed reversed playback, fixed bounce autoplay, updated readme with missing property (1fa0f44)

1.3.0 (2021-12-16)

Bug Fixes

  • add web worker: add web worker (a7f9491)
  • count off by 1: count adds an extra 1 as it starts from 0 (f4efda4)
  • css changes: positioning issues fixed where lottie was overflowing out of container (965823c)
  • css fix: safari glitch error fix (39dad7b)
  • height calculation fic: height calculation should happen only if controls are keyed in. bugfix (7ac35d2)
  • missing build file: missing build file. tgs player.js (be764ec)
  • small updates: changelog, tests for interactivity lib breakage, lang added to aria labels (f1c0543)
  • version bump: version bump (4edc7c4)
  • version bump: version bump (49dbde2)
  • web worker mangling issue: web worker mangling issue (1c2632c)

Features

  • a11y: fix focus and tabindex (0dfecbc)
  • accessibility: added lang attribute to control buttons (388c826)
  • add web worker prop: added webworker prop (8a19443)
  • bump lottie web: bump lottie web version to latest (f1f3422)
  • player container: added role on div container (5dd8868)
  • web worker: web worker bundling (c1c09da)

Changelog

All notable changes to this project will be documented in this file. The format is based on Keep a Changelog and this project adheres to Semantic Versioning, enforced with semantic-release.

1.5.4

  • Fix focus with a css outline on button
  • Fix tabindex when you have multiple animation on the same page
  • Hide svg element from focus list
  • Add a way to hide the slider for some animation
  • add role to div container to prevent lighthouse warnings

1.5.3

Bug Fixes

  • Missing tgs player.js file added

1.5.2

Bug Fixes

  • Lang tag added, tests added to test for breakage of interactivity library.

1.5.1

Bug Fixes

  • web-worker: fixed web worker prop to work correctly with proper bundling adjustments.

1.5.0

Bug Fixes

  • web-worker: added web worker prop.

1.4.5

Bug Fixes

  • loop: loop counter started at zero. changed to 1 instead.

1.4.4

Bug Fixes

  • resize: fixed width and height responsiveness issues

1.4.3

Bug Fixes

  • safari: fixed safari glitching animation issue (used flex for controls placement instead of grid system)

1.4.2

Bug Fixes

  • code: fixed typescript errors with type assertions and restructuring of code

1.4.1

Bug Fixes

  • code: fixed typescript errors with type assertions and restructuring of code
  • container: added width and height inheritence to animation container

1.4.0

Features

  • event listeners: added event listeners before json error check
  • cleanup: added a destroy method for cleanup of dom

1.3.1

Chore

  • rollback: rollback previous changes

1.3.0

Bug Fixes

  • network call fix: attempt to fix dual network call

1.2.1 (2021-09-30)

Bug Fixes

  • safari fix: safari height width inherit to container, eslint error fixes (8c96be5)

1.2.0 (2021-09-21)

Features

  • events and cleanup: added event listeners before json error check and added a destroy method for cleanup (646d63b)

1.1.4 (2021-09-02)

Bug Fixes

  • rollback: rollback due to race condition issues (556307f)

1.1.3 (2021-09-02)

Bug Fixes

  • asset path bug fix: asset path bug fix (27d24e7)

1.1.2 (2021-09-01)

Bug Fixes

  • cleanup: cleanup (339c0cb)
  • network calls: removed redundant network call to json url (8726536)

1.1.1 (2021-07-06)

Bug Fixes

  • player.ts: race condition bug fix (3a57dba)

1.1.0 (2021-07-05)

Bug Fixes

  • duplicate method: duplicate method bug fix (7b09f39)

Features

  • err handling: err handling (8ac685f)

1.0.0 (2021-06-22)

Bug Fixes

  • player.tsx: race condition fix (9ec58ef)

Features

  • accessibility: added aria labels, and roles needed for voiceover tools,added keyboard ctrls (1a76011)
  • added basic sanity checks/tests (e6ebe61)
  • added lerna, sample project using local dependency (59d0bc0)
  • fix tests, add sample lottie (823a104)
  • package bump: lottie web version bump (71d5339)
  • packages: lottie web engine bump to 5.7.8 (f4e1a94)