Search code examples
javascriptanimationlottiebodymovin

How can I trigger an event once Lottie animation reaches a certain frame?


Using Lottie/BodyMoving, how can I trigger an event once the Lottie animation reaches a certain frame.

For example: Once anim1 reaches a certain frame, I want anim2 to play.

Thanks


Solution

  • try enterFrame event

      const anim = lottie.loadAnimation({ ...options, path: 'URL_TO_JSON' });
    anim.addEventListener('enterFrame', () => {
      console.log('enterFrame', anim.currentFrame);
      if(anim.currentFrame == 55)
      {
      //stop and play 2nd one
      }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bodymovin/5.5.9/lottie.js"></script>
     <div style="width:1067px;height:600px"  class="lottie" data-animation-path="animation/" data-anim-loop="true" data-name="ninja"></div>