Jump to content
Search Community

Scrolltrigger timeline + forEach

Juc1 test
Moderator Tag

Go to solution Solved by tailbreezy,

Recommended Posts

Hi all,

 

I want to say:

when image 1 enters the viewport, run the timeline on image 1

when image 2 enters the viewport, run the timeline on image 2

etc

 

But so far I am getting - when image 1 enters the viewport, run the timeline on all the images at the same time.

 

Can anyone please correct my pen?

 

Thanks... 

See the Pen PobjKPj by Juc1 (@Juc1) on CodePen

Link to comment
Share on other sites

  • 2 years later...
On 2/18/2021 at 5:15 PM, tailbreezy said:

 Also you will need some height/spacer at the end because you will not be able to reach the last trigger.

 

What exactly do you mean by that? I am having actually issues with forEach timelines which are triggered too early maybe due to the fact that previous sections are pinned with end: +-400% and stuff like that.

Very hard to understand the logic of gsap looking at the browser console when everything is wrapped in these pin spacer containers.…

 

Fact is that sometimes timelines get triggered before the trigger element actually enters the viewport.

Link to comment
Share on other sites

Hello @Garavani

I'm sorry to hear about your issues.

Unfortunatelly 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 Stackblitz that demonstrates the issue? Even better would be if you could create a new thread for your question, providing that minimal demo there.

 

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

 

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. 

Link to comment
Share on other sites

First of all: great library, great support!

Sometimes, though, it is too hard and time consuming to REbuild an issue that most probably will not even persist in a totally new minimal demo environment.

I simply hoped that any hint on this “height/spacer” remark could give me an idea.

Anyhow, thanks a lot! I will go on doing some research. 

Link to comment
Share on other sites

I found the answer to my troubles in the answer of OSUblake in this thread: 

I was never aware that we need to “sort” the timelines in the code according to the real succession on the site! 

However, so it becomes hard to do forEach loops with timelines if you have different animations in between them…

Let’s say we have in a page layout:

1) section [timelineType1]

2) section “some specific individual timeline”

3) section [timelineType1]

4) section “some other specific individual timeline”

5) section “and another specific individual timeline”

6) section [timelineType1]

We’d have to repeat the code (const = gsap…) to be able to place it in the correct order…

 

Link to comment
Share on other sites

Not sure if there's a question here or if you figured it out? But just incase - That's where  refreshPriority comes in

From the scrollTrigger docs
 

Quote

refreshPriority    number -
It's VERY unlikely that you'd need to define a refreshPriority as long as you create your ScrollTriggers in the order they'd happen on the page (top-to-bottom or left-to-right) which we strongly recommend doing. Otherwise, use refreshPriority to influence the order in which ScrollTriggers get refreshed to ensure that the pinning distance gets added to the start/end values of subsequent ScrollTriggers further down the page (that's why order matters). See the sort() method for details. A ScrollTrigger with refreshPriority: 1 will get refreshed earlier than one with refreshPriority: 0 (the default). You're welcome to use negative numbers too, and you can assign the same number to multiple ScrollTriggers.

 

  • Like 2
Link to comment
Share on other sites

Thank you Cassie!

This helped a lot. In fact I came to this in the docs after I understood where my problem was.

And sorry for having stepped in this topic that in reality hadn’t much to do with my problem in the end. So for me it is solved!

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