Volver al ranking

LottieFiles/lottie-player

TypeScript

Lottie viewer/player as an easy to use web component! https://lottiefiles.com/web-player

web-componentlit-elementlottielottie-webbodymovin
Crecimiento de estrellas
Estrellas
1.7k
Forks
182
Crecimiento semanal
Issues
54
5001k1.5k
may 2019sept 2021feb 2024jul 2026
Artefactosnpmnpm install lottie-player
README

[!IMPORTANT] @lottiefiles/lottie-player is deprecated and no longer maintained.

Please use @lottiefiles/dotlottie-wc instead, a modern web component for playing Lottie and dotLottie animations.


lottie-player Web Component (Deprecated)

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

Repositorios relacionados
css-doodle/css-doodle

A web component for visual art and creative coding

JavaScriptnpmMIT Licensecsspatterns
css-doodle.com
6k209
salesforce/lwc

⚡️ LWC - A Blazing Fast, Enterprise-Grade Web Components Foundation

JavaScriptnpmOtherlwcsalesforce
lwc.dev
1.8k448
UI5/webcomponents

UI5 Web Components - the enterprise-flavored sugar on top of native APIs! Build SAP Fiori user interfaces with the technology of your choice.

TypeScriptnpmApache License 2.0open-sourceui5
ui5.github.io/webcomponents/
1.8k284
duetds/date-picker

Duet Date Picker is an open source version of Duet Design System’s accessible date picker. Try live example at https://duetds.github.io/date-picker/

TypeScriptnpmMIT Licensejavascriptjavascript-library
duetds.com
1.7k74
WickyNilliams/cally

Small, feature-rich calendar components

TypeScriptnpmMIT Licenseweb-componentdatepicker
wicky.nillia.ms/cally/
1.6k32
SAP/ui5-webcomponents

UI5 Web Components - the enterprise-flavored sugar on top of native APIs! Build SAP Fiori user interfaces with the technology of your choice.

TypeScriptnpmApache License 2.0open-sourceui5
sap.github.io/ui5-webcomponents/
1.6k273
TonyGermaneri/canvas-datagrid

Canvas based data grid web component. Capable of displaying millions of contiguous hierarchical rows and columns without paging or loading, on a single canvas element.

JavaScriptnpmBSD 3-Clause "New" or "Revised" Licensedatagriddatatable
1.6k205
jhildenbiddle/css-vars-ponyfill

Client-side support for CSS custom properties (aka "CSS variables") in legacy and modern browsers

JavaScriptnpmMIT Licenseclientclient-side
jhildenbiddle.github.io/css-vars-ponyfill
1.5k63
bitjson/qr-code

A no-framework, no-dependencies, customizable, animate-able, SVG-based <qr-code> HTML element.

TypeScriptnpmMIT Licensebchbitcoin
qr.bitjson.com
1.4k84
justinribeiro/lite-youtube

The fastest little YouTube web component on this side of the internet. The shadow dom web component version of Paul's lite-youtube-embed.

TypeScriptnpmMIT Licenseweb-componentvanilla-webcomponent
npmjs.com/package/@justinribeiro/lite-youtube
1.4k95
tur-nr/polymer-redux

Polymer bindings for Redux.

JavaScriptnpmpolymerredux
tur-nr.github.io/polymer-redux
44067