Jump to content
Search Community

ScrollTrigger - Syncing animated text with Lottie animation

NZZ Editorial Tech test
Moderator Tag

Go to solution Solved by OSUblake,

Recommended Posts

Hi

 

I'm using the ScrollTrigger to scroll through a Lottie animation using the following settings:

animation = lottie.loadAnimation({...});
                                  
ScrollTrigger.create({
  trigger: lottieTrigger,
  start: "top top",
  end: "+=750%",
  scrub: true,
  pin: true,
  // markers: true,
  onUpdate: self => {
    animation.goToAndStop(self.progress * (animation.totalFrames - 1), true);
  }
});

So far so good. The animation I use has "scenes" with a length of 4 seconds each. Now, I want to animate some text to fly over every scene.

 

What's the best way to do that? I tried using a Timeline, but the timing gave me a headache. I wasn't able to time the texts in a way, that each one flies in at exactly the start of a "scene" and disappears on top before the next "scene" starts.

 

Any help is greatly appreciated.

 

Greetings

Nick

See the Pen BaWvQdz?editors=1010 by 12_nick (@12_nick) on CodePen

Edited by NZZ Editorial Tech
Link to comment
Share on other sites

You can include your lottie animation in the timeline.

 

let playhead = {frame: 0};

let tl = gsap.timeline({
  scrollTrigger: {...}
});

tl.to(playhead, {
  frame: animation.totalFrames - 1,
  ease: "none",
  onUpdate: () => animation.goToAndStop(playhead.frame, true), 
}, 0)
  .to(...)

  

 

  • Like 3
Link to comment
Share on other sites

Thanks guys for your answers. They did help, but I'm still kinda confused about the whole timing.

 

I had some time now to make an illustration (I added it on top. How do I add a CodePen in a reply? 😅).

 

My goal is to sync the two texts to the Lottie. The Lottie is around 3 seconds long (181 frames at 60 fps). How do I set the TimeLine correctly, so that the first text flies over at second 1 of the Lottie (and the second text at second 2, etc.)?

 

Greetings

Nick

Link to comment
Share on other sites

  • Solution
8 hours ago, NZZ Editorial Tech said:

How do I add a CodePen in a reply?

 

Just paste the url.

 

8 hours ago, NZZ Editorial Tech said:

How do I set the TimeLine correctly, so that the first text flies over at second 1 of the Lottie (and the second text at second 2, etc.)?

 

You can fine tune it with durations and the position parameter

 


  tl.fromTo(".text1", {y: 500}, {y: -500, duration: 1}, 1);
  tl.fromTo(".text2", {y: 500}, {y: -500, duration: 1}, 2);

 

 

 

  • Like 4
Link to comment
Share on other sites

3 hours ago, OSUblake said:

Just paste the url.

Ah, so simple :) Thanks!

 

3 hours ago, OSUblake said:

You can fine tune it with durations and the position parameter

See, I knew about the position parameter, but I think using it with a Lottie animation had me confused. I think I got it now, thanks to posting my issue here and going through my code again step by step.

 

Thanks for all the replies.

 

Greetings

Nick

  • Like 3
Link to comment
Share on other sites

 

Since durations (and thus the position parameter) work a bit different on scrubbing ScrollTrigger tweens/timelines than they do on regular time-based tweens/timelines, it might be worth checking that explanation out, too.

 

https://greensock.com/docs/v3/Plugins/ScrollTrigger#scrub

 

(It is mentioned in a comment underneath the position parameter section but might be overseen)

 

  • Like 3
Link to comment
Share on other sites

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...