Jump to content
Search Community

Added tweens to a master timeline with ScrollTrigger are autoplayed using GSAP and Three JS

eseka test
Moderator Tag

Recommended Posts

Hello !

After a lot of time using GSAP I don't really understand why this is happening. It is a very simple use case. 

First I create the Master timeline that is fired by ScrollTrigger

this.master = new GSAP.timeline({
      scrollTrigger: {
        trigger: ".scroll-controls",
        start: "top top",
        end: "bottom bottom",
        scrub: 1,
        immediateRender: false,
      },
    });

then I add some tweens and finally I build the master timeline

 cuadro0() {
    let tl = new GSAP.timeline({ immediateRender: false,  });

    tl.fromTo(this.camera.position, { x: -5.9 }, { x: -4.1, z: 4.7 }).to(
      this.camera.rotation,
      {
        y: -3,
      }
    );

    return tl;
  }

buildMaster() {
    this.master.add(this.pasillo0());
    this.master.add(this.cuadro0());
  }

The expected behaviour is to wait to reach the ScrollTrigger section to play the timeline but the reality is that everything is played on page load...

 

what is happening? 

 

I tried many approach like pausing it, disabling it... but no way 😕

 

Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 

 

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

 

Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

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

 

If you're using something like React/Next/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.

 

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

Link to comment
Share on other sites

Indeed, it's pretty much impossible to troubleshoot without a minimal demo, but I noticed one problem for sure: 

// bad
let tl = new GSAP.timeline({ immediateRender: false,  });

// good
let tl = gsap.timeline();

You should NOT have the "new" keyword there and there's no such thing as setting immediateRender on a timeline. That's only for tweens. 

 

This also looked suspicious to me: 

start: "top top",
end: "bottom bottom",

That would only work if your ".scroll-controls" element is taller than the viewport itself. Imagine that it is actually height: 100vh...that would mean that when the top hits the top (your start), the bottom would also hit the bottom at the very same time! And if it's shorter than the viewport, the end would get triggered before the start. 

 

If you still need help, please make sure you provide a minimal demo👍

Link to comment
Share on other sites

4 hours ago, GreenSock said:

Indeed, it's pretty much impossible to troubleshoot without a minimal demo, but I noticed one problem for sure: 

// bad
let tl = new GSAP.timeline({ immediateRender: false,  });

// good
let tl = gsap.timeline();

You should NOT have the "new" keyword there and there's no such thing as setting immediateRender on a timeline. That's only for tweens. 

 

This also looked suspicious to me: 

start: "top top",
end: "bottom bottom",

That would only work if your ".scroll-controls" element is taller than the viewport itself. Imagine that it is actually height: 100vh...that would mean that when the top hits the top (your start), the bottom would also hit the bottom at the very same time! And if it's shorter than the viewport, the end would get triggered before the start. 

 

If you still need help, please make sure you provide a minimal demo👍

 

Many thanks ! You're right in both.

I was thinking that everything was played but then I realized that it was playing until certain point... so it was a concept problem about the layout and the markup + css. 

 

Here is the demo where it works as it should

 

See the Pen QWVzwdq by alvarindev (@alvarindev) on CodePen

 

In my case also I had some elements above the ".scroll-controls" that after some time I hidde by using display:none. Also I'm using scrollTrigger.refresh() when I do that. 

 

THX

 

 

  • Like 2
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...