Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-lottie

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-lottie

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
84K
increased by2.57%
Maintainers
1
Weekly downloads
 
Created
Source

A minimal customizable performance-stable Angular component for rendering After Effects animations.

Build status Licence: MIT npm version David

Table of contents

Features

  • rich: ngx-lottie provides more opportunities to work with API exposed by Lottie
  • strict: all types of objects and events are available to you
  • performant: the lottie library is loaded on demand

Quick example

<ng-lottie
  width="600"
  height="500"
  containerClass="moving-box"
  [options]="options"
  (animationCreated)="animationCreated($event)"
  (configReady)="configReady()"
  (dataReady)="dataReady()"
  (domLoaded)="domLoaded()"
  (enterFrame)="enterFrame($event)"
  (segmentStart)="segmentStart($event)"
  (complete)="complete($event)"
  (loopComplete)="loopComplete($event)"
  (destroy)="destroy($event)"
></ng-lottie>

Installation

To install ngx-lottie run the following command:

npm i ngx-lottie
# or if you're using yarn
yarn add ngx-lottie

Usage

First, import the LottieModule to any of your modules:

import { NgModule } from '@angular/core';
import { LottieModule } from 'ngx-lottie';

@NgModule({
  imports: [
    LottieModule
  ]
})
export class AppModule {}

Now you can simple use an ng-lottie component and provide your custom options via the options binding:

import { Component } from '@angular/core';
import { LottieOptions, AnimationItem } from 'ngx-lottie';

@Component({
  selector: 'app-root',
  template: `
    <ng-lottie
      [options]="options"
      (animationCreated)="animationCreated($event)"
    ></ng-lottie>
  `
})
export class AppComponent {
  public options: LottieOptions = {
    path: '/assets/animation.json'
  };

  public animationCreated(animationItem: AnimationItem): void {
    console.log(animationItem);
  }
}

Also it's possible to use a lottie directive if you'd like to provide your own custom container and play with it:

import { Component } from '@angular/core';
import { LottieOptions, AnimationItem } from 'ngx-lottie';

@Component({
  selector: 'app-root',
  template: `
    <main
      lottie
      [options]="options"
      (animationCreated)="animationCreated($event)"
    ></main>
  `
})
export class AppComponent {
  public options: LottieOptions = {
    path: '/assets/animation.json'
  };

  public animationCreated(animationItem: AnimationItem): void {
    console.log(animationItem);
  }
}

API

Bindings

@Input()TypeRequiredDefaultDescription
optionsLottieOptionsrequired{ renderer: 'svg', loop: true, autoplay: true }Configuration that's used by AnimationItem
widthstringoptionalnullCustom container width
heightstringoptionalnullCustom container height
stylesLottieCSSStyleDeclarationoptionalnullCustom container styles
containerClassLottieContainerClassoptionalnullCustom class applied to the container

Events

@Output()TypeRequiredDescription
animationCreatedAnimationItemoptionalDispatched after the lottie successfully creates animation
configReadyvoidoptionalDispatched after the needed renderer is configured
dataReadyvoidoptionalDispatched when all parts of the animation have been loaded
dataFailedvoidoptionalDispatched if the XMLHttpRequest, that tried to load animation data using provided path, has errored
domLoadedvoidoptionalDispatched when elements have been added to the DOM
enterFrameBMEnterFrameEventoptionalDispatched after entering the new frame
segmentStartBMSegmentStartEventoptionalDispatched when the new segment is adjusted
loopCompleteBMCompleteLoopEventoptionalDispatched after completing frame loop
completeBMCompleteEventoptionalDispatched after completing the last frame
loadedImagesvoidoptionalDispatched after all assets are preloaded
destroyBMDestroyEventoptionalDispatched in the ngOnDestroy hook of the service that manages lottie's events, it's useful for releasing resources

Optimizations

The ng-lottie component is marked with OnPush change detection strategy. This means it will not be checked in any phase of the change detection mechanism until you change the reference to some binding. For example if you use an svg renderer and there are a lot DOM elements projected - you would like to avoid checking this component, as it's not necessary.

Also, events, dispatched by AnimationItem, are listened outside Angular's zone, thus you shouldn't worry that every dispatch will be intercepted by Angular's zone.

Keywords

FAQs

Package last updated on 10 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc