Jump to content
Search Community

Applying dotLottie-web on GSAP Timeline

arno.oost
Moderator Tag

Go to solution Solved by arno.oost,

Recommended Posts

arno.oost
Posted

I'm working on an assignment for school. When the page loads in, it'll reveal the "hero image" (main screen) bit by bit automatically without requiring user assistance. Now I'm trying to integrate my dotLottie animation into the timeline but I'm having a really hard time doing so. I've scanned this forum for any possible answer, asked generative AI bots as well as classmates but nobody's solution seems to work. 

 

Here's my current "animations.js" file. I'm building a Vite site and have GSAP & dotLottie-web imported through NPM.

 

import { gsap } from "gsap";
 
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { DotLottie } from '@lottiefiles/dotlottie-web';
 
gsap.registerPlugin(ScrollTrigger);
 
const heroImgLottie = new DotLottie({
  autoplay: false,
  loop: false,
  canvas: document.querySelector('#heroIMG'),
  src: "src/assets/lottie/heroimg.lottie"
});
 
let hero_tl = gsap.timeline({
  onComplete: heroImgLottie.play(),
});
 
// Loader
hero_tl.to('.loader_content', { duration: 0.25, delay: 3.5, opacity: 0, })
hero_tl.to('.loader_bar', { duration: 1.5, height: 0, stagger: { amount: 0.5, }, ease: "power4.inOut", })
hero_tl.to('.loader', { duration: 0, display:"none"})
hero_tl.from('.hero_title', { duration: .5, y: 100, opacity: 0, ease: "power4.out", })
hero_tl.to('.nav_options', { duration: .5, opacity: 1, ease: "power4.inOut", })
GSAP Helper
Posted

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen.

that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

mvaneijgen
Posted

Hi @arno.oost welcome to the forum!

 

Seems more like an issue with dotlottie then with GSAP, I have the feeling, GSAP is doing its thing right? You could convert your onComplete call back to a function onComplete: () => {console.log('done); heroImgLottie.play();}, to see if it is getting triggered, which would be the case I would figure. 

 

This is normally not how we work on the forum, but seen that your new here. I've searched some Lottie examples and found a random demo and it seems to not have a .play() function, see demo below. So you have to find there equivalent function to play your animation. As mentioned above, always include a minimal demo with your question, so that anyone who wants to help you can dive in to the code directly and help you debug! 

 

Hope it helps and happy tweening!  

 

See the Pen KwPBYLr by mvaneijgen (@mvaneijgen) on CodePen.

 

 

  • Like 1
arno.oost
Posted

Hey @mvaneijgen, yea sorry for not including a CodePen. The rest of the timeline works perfectly as you predicted so the issue lies with dotLottie-web for sure. I'll try to figure it out further on my own. If I find the solution I'll post it here in case other people run into the same issue. Thank you for the quick response!

  • Solution
arno.oost
Posted

Update for those in a similar situation: My professor managed to find a fix for this. There's a bug in the current way dotLottie-web handles rendering and requires a simple addition to the animation object to fix. Adding the code in the picture (highlighted) fixed it!

 

image.png.c6d9a9964cb0477ec00ebb6a4093ab32.png

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...