LottieFiles / dotlottie-web

Official LottieFiles player for rendering Lottie and dotLottie animations in the web. Supports React, Vue, Svelte, SolidJS and Web Components.
https://developers.lottiefiles.com/docs/dotlottie-player/
MIT License
191 stars 11 forks source link

"intermission" doesnt seems supported (migrating from the old player) #318

Closed SquirrelDeveloper closed 3 months ago

SquirrelDeveloper commented 3 months ago

Overview

Hi, The intermission parameter of the react player doesn't seem implemented (I am migrating from the old player that had this option) Any plan to support it in the future ?

Regards

Type

theashraf commented 3 months ago

Hi @SquirrelDeveloper, We don't have plans to support the intermission parameter at the moment, but you can easily achieve the same behavior with just a couple of extra lines of code. By adding an event listener for the complete event and using setTimeout, you can implement the intermission before replaying the animation.

import { DotLottie } from "https://esm.sh/@lottiefiles/dotlottie-web";

// Define the duration of the intermission between animation loops in milliseconds
const intermission = 1000; // 1 second

const dotLottie = new DotLottie({
  canvas: document.querySelector("#dotLottie-canvas"),
  src: "https://lottie.host/9ac9c440-c19e-4ac9-b60e-869b6d0ef8cb/7h97gYMCNE.lottie",
  autoplay: true
});

// Add an event listener to the dotLottie instance that triggers when the animation completes
dotLottie.addEventListener("complete", () => {
  // Set a timeout to pause for the intermission duration, then replay the animation
  setTimeout(() => dotLottie.play(), intermission);
});

You can also check out this CodePen example: https://codepen.io/lottiefiles/pen/PorQjXg

theashraf commented 3 months ago

@SquirrelDeveloper, I just noticed you're using dotLottie-react. I've also provided a React example showing how you can achieve the intermission behavior. It's quite similar to the previous example I shared, but this one is specifically for dotLottie-react.

You can check it out here: https://codepen.io/lottiefiles/pen/mdZXwov

theashraf commented 3 months ago

@SquirrelDeveloper, I'm closing this issue. If you encounter any problems with the provided approach, please feel free to reopen it. Thanks!

SquirrelDeveloper commented 3 months ago

@theashraf Thanks a lot for your detailed response, it helped me a lot, Regards