Convert Figma logo to code with AI

LottieFiles logolottie-player

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

1,539
172
1,539
72

Top Related Projects

Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/

Render After Effects animations natively on Android and iOS, Web, and React Native

An iOS library to natively render After Effects vector animations

Lottie wrapper for React Native.

Render After Effects animations on Vue based on Bodymovin

Quick Overview

LottieFiles/lottie-player is an open-source web component for rendering and controlling Lottie animations. It provides a simple and efficient way to add high-quality, scalable animations to web projects without the need for heavy video files or complex JavaScript libraries.

Pros

  • Easy integration with various web frameworks and vanilla JavaScript
  • Lightweight and performant, optimized for web use
  • Supports a wide range of Lottie animation features and controls
  • Active development and community support

Cons

  • Limited browser support for older versions (IE11 and below)
  • May require additional setup for certain frameworks or build systems
  • Some advanced Lottie features might not be fully supported
  • Performance can degrade with very complex animations

Code Examples

  1. Basic usage:
<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>
<lottie-player
  src="https://assets2.lottiefiles.com/packages/lf20_UJNc2t.json"
  background="transparent"
  speed="1"
  style="width: 300px; height: 300px;"
  loop
  autoplay
></lottie-player>
  1. Controlling animation with JavaScript:
const player = document.querySelector("lottie-player");
player.addEventListener("load", () => {
  // Play segment from frame 0 to 50
  player.playSegments([0, 50], true);
});

// Pause animation
player.pause();

// Set speed to 2x
player.speed = 2;
  1. React component usage:
import React from "react";
import "@lottiefiles/lottie-player";

const App = () => (
  <lottie-player
    src="https://assets2.lottiefiles.com/packages/lf20_UJNc2t.json"
    background="transparent"
    speed="1"
    style={{ width: "300px", height: "300px" }}
    loop
    autoplay
  ></lottie-player>
);

export default App;

Getting Started

  1. Install the package:
npm install @lottiefiles/lottie-player
  1. Import and use in your project:
<script src="node_modules/@lottiefiles/lottie-player/dist/lottie-player.js"></script>
<lottie-player
  src="path/to/animation.json"
  background="transparent"
  speed="1"
  style="width: 300px; height: 300px;"
  loop
  autoplay
></lottie-player>

For more advanced usage and framework-specific integration, refer to the official documentation.

Competitor Comparisons

Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/

Pros of lottie-web

  • More mature and widely adopted, with a larger community and ecosystem
  • Offers more advanced features and customization options
  • Supports a broader range of animation types and effects

Cons of lottie-web

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve for beginners
  • Requires more setup and configuration

Code Comparison

lottie-web:

import lottie from 'lottie-web';

const animation = lottie.loadAnimation({
  container: document.getElementById('lottie-container'),
  renderer: 'svg',
  loop: true,
  autoplay: true,
  path: 'animation.json'
});

lottie-player:

<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>

<lottie-player
  src="https://assets2.lottiefiles.com/packages/lf20_UJNc2t.json"
  background="transparent"
  speed="1"
  style="width: 300px; height: 300px;"
  loop
  autoplay
></lottie-player>

Summary

lottie-web is a more powerful and flexible solution for advanced users and complex projects, while lottie-player offers a simpler, more accessible approach for quick implementation and basic use cases. The choice between the two depends on the specific requirements of your project and your level of expertise in working with Lottie animations.

Render After Effects animations natively on Android and iOS, Web, and React Native

Pros of lottie-android

  • Native Android support with optimized performance
  • Extensive documentation and community support
  • Seamless integration with Android development workflows

Cons of lottie-android

  • Limited to Android platform
  • Requires Java/Kotlin knowledge for implementation
  • Larger file size compared to web-based alternatives

Code Comparison

lottie-android:

val animationView = findViewById<LottieAnimationView>(R.id.animation_view)
animationView.setAnimation(R.raw.animation)
animationView.playAnimation()

lottie-player:

<lottie-player
  src="https://assets5.lottiefiles.com/packages/lf20_UJNc2t.json"
  background="transparent"
  speed="1"
  style="width: 300px; height: 300px;"
  loop
  autoplay
></lottie-player>

lottie-android is specifically designed for Android development, offering native support and optimized performance for mobile applications. It integrates seamlessly with Android development workflows and has extensive documentation and community support.

However, lottie-android is limited to the Android platform and requires Java/Kotlin knowledge for implementation. It also has a larger file size compared to web-based alternatives like lottie-player.

lottie-player, on the other hand, is a web component that can be easily integrated into web applications using HTML. It offers cross-platform compatibility and simpler implementation, but may not provide the same level of performance optimization for Android devices as lottie-android.

An iOS library to natively render After Effects vector animations

Pros of lottie-ios

  • Native iOS implementation, optimized for performance on Apple devices
  • Extensive support for iOS-specific features and animations
  • Tighter integration with iOS development workflows and tools

Cons of lottie-ios

  • Limited to iOS platform, not cross-platform like lottie-player
  • Requires more iOS-specific knowledge to implement and customize
  • May have a steeper learning curve for developers not familiar with iOS development

Code Comparison

lottie-ios:

let animationView = AnimationView(name: "animation")
animationView.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
animationView.contentMode = .scaleAspectFit
animationView.loopMode = .loop
animationView.play()
view.addSubview(animationView)

lottie-player:

<lottie-player
  src="https://assets2.lottiefiles.com/packages/lf20_UJNc2t.json"
  background="transparent"
  speed="1"
  style="width: 300px; height: 300px;"
  loop
  autoplay
></lottie-player>

The code comparison shows that lottie-ios requires Swift code for implementation, while lottie-player uses a simple HTML tag, making it easier to integrate into web projects.

Lottie wrapper for React Native.

Pros of lottie-react-native

  • Specifically designed for React Native, offering seamless integration with React Native projects
  • Provides native performance optimizations for mobile platforms
  • Offers more React Native-specific features and components

Cons of lottie-react-native

  • Limited to React Native projects, not suitable for web or other platforms
  • May require additional setup and configuration compared to the more versatile lottie-player
  • Potentially steeper learning curve for developers not familiar with React Native

Code Comparison

lottie-react-native:

import LottieView from 'lottie-react-native';

<LottieView
  source={require('./animation.json')}
  autoPlay
  loop
/>

lottie-player:

<lottie-player
  src="https://assets2.lottiefiles.com/packages/lf20_UJNc2t.json"
  background="transparent"
  speed="1"
  style="width: 300px; height: 300px;"
  loop
  autoplay
></lottie-player>

The lottie-react-native example shows how to use the component in a React Native environment, while the lottie-player example demonstrates its usage in HTML. The syntax and attributes differ due to the different platforms they target.

Render After Effects animations on Vue based on Bodymovin

Pros of vue-lottie

  • Specifically designed for Vue.js integration, making it easier to use in Vue projects
  • Lightweight and focused on Vue functionality
  • Provides Vue-specific methods and props for better control within Vue components

Cons of vue-lottie

  • Less frequently updated compared to lottie-player
  • Fewer features and customization options
  • Limited to Vue.js projects, not as versatile for other frameworks or vanilla JavaScript

Code Comparison

vue-lottie:

<template>
  <lottie :options="lottieOptions" :height="300" :width="300" v-on:animCreated="handleAnimation"/>
</template>

<script>
import lottie from 'vue-lottie'
import animationData from './animation.json'

export default {
  components: { lottie },
  data() {
    return {
      lottieOptions: { animationData }
    }
  },
  methods: {
    handleAnimation(anim) {
      this.anim = anim
    }
  }
}
</script>

lottie-player:

<lottie-player
  src="https://assets2.lottiefiles.com/packages/lf20_UJNc2t.json"
  background="transparent"
  speed="1"
  style="width: 300px; height: 300px;"
  loop
  autoplay
></lottie-player>

The vue-lottie example shows Vue-specific integration, while lottie-player demonstrates a more straightforward HTML implementation that can be used in various contexts.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

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 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!

Our other Lottie related libraries

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

NPM DownloadsLast 30 Days