Getting Started
Introduction
dotLottie-wc
is a web component that allows you to easily embed Lottie animations in your web applications. It is a wrapper around the dotLottie-web library.
Installation
npm install @lottiefiles/dotlottie-wc
Usage
Via npm
After installation, you can use dotlottie-wc
in your HTML file:
<dotlottie-wc src="https://lottie.host/4db68bbd-31f6-4cd8-84eb-189de081159a/IGmMCqhzpt.lottie" autoplay="true" loop="true"></dotlottie-wc>
And import it in your JavaScript or TypeScript module:
import '@lottiefiles/dotlottie-wc';
Via CDN
You can also use the component directly via a npm CDN:
<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8" /> <title>@lottiefiles/dotlottie-wc | Basic Example</title></head><body> <dotlottie-wc src="https://lottie.host/4db68bbd-31f6-4cd8-84eb-189de081159a/IGmMCqhzpt.lottie" autoplay loop></dotlottie-wc> <script type="module" src="https://unpkg.com/@lottiefiles/dotlottie-wc@latest/dist/dotlottie-wc.js"></script></body></html>
Properties
The dotlottie-wc
exposes the following properties:
Property name | Type | Description |
---|---|---|
dotLottie | DotLottie | The dotLottie instance from DotLottie, allowing you to call methods and listen to events for more control over the animation. |
Methods
You can call all DotLottie methods via the dotLottie
property:
Playback Control
play()
- Start/resume animationpause()
- Pause animationstop()
- Stop animationsetFrame(frame: number)
- Jump to specific frame
Configuration
setSpeed(speed: number)
- Set animation speedsetLoop(loop: boolean)
- Set loop behaviorsetMode(mode: Mode)
- Set playback mode
Animation Management
loadAnimation(animationId: string)
- Load specific animationsetMarker(marker: string)
- Set marker to play from
Theme Management
setTheme(themeId: string)
- Apply themesetThemeData(themeData: string)
- Apply theme from data
For complete methods documentation, see the web package API reference.
Events
You can listen to all DotLottie events via the dotLottie
property:
Animation Events
load
- Animation data loaded successfullyloadError
- Animation loading failed ({ error: Error }
)ready
- WASM module loaded and readyplay
- Animation started playingpause
- Animation pausedstop
- Animation stoppedcomplete
- Animation completedloop
- Animation looped ({ loopCount: number }
)frame
- Frame changed ({ currentFrame: number }
)
Example Usage
const dotLottieElement = document.querySelector('dotlottie-wc');
// Wait for the element to be readydotLottieElement.addEventListener('ready', () => { // Access the DotLottie instance const dotLottie = dotLottieElement.dotLottie;
// Listen to events dotLottie.addEventListener('play', () => console.log('Playing')); dotLottie.addEventListener('complete', () => console.log('Complete'));
// Control playback setTimeout(() => dotLottie.pause(), 2000);});
For complete events documentation, see the web package events.