Jump to content
Search Community

Let animation in scroll trigger timeline run in the background

Garavani test
Moderator Tag

Go to solution Solved by mvaneijgen,

Recommended Posts

Hello all,

 

hopefully this can be answered without a code pen as it is (I guess) a quite simple and generic question.

 

I have the following scrollTigger timeline:

 

const image2 = gsap
  .timeline({
    scrollTrigger: {
      trigger: "#image-2",
      pin: true,
      scrub: true
    }
  })
  .to(".top-color", {
    "--r": 73,
    "--g": 57,
    "--b": 51,
    "--a": 0.77
  }, 0)
  .to("#image-2 .dimmer", {
    "--gradient-middle": "25%"
  }, 0.5)
  .to("#image-2 .dimmer", {
    "--gradient-alpha": 0
  }, 1)

 

which works well. Animations expanding while the #image-2 is in view.

They should run from 0 to 100% of the timeline.

 

Now when I want to add other animations as the ones in italic:

 

const image2 = gsap
  .timeline({
    scrollTrigger: {
      trigger: "#image-2",
      pin: true,
      scrub: true
    }
  })
  .to(".top-color", {
    "--r": 73,
    "--g": 57,
    "--b": 51,
    "--a": 0.77
  }, 0)
  .to("#image-2 .dimmer", {
    "--gradient-middle": "25%"
  }, 0.5)
  .to("#image-2 .dimmer", {
    "--gradient-alpha": 0
  }, 1)
  .to("#detail-image-1", {
    y: "50vh"
  }, 0.5)
  .to("#detail-image-2", {
    y: "-30vh"
  }, 0.5)
;

 

The new ones work as expected, too. Only that they steal seemingly the time the first ones had to roll out completely. How can I avoid this?

The first ones should always work, let’s say “in background” while the other ones above an be added without interfering and not shortening the times.

 

Many thanks in advance!

Link to comment
Share on other sites

Are you sure you're using the position parameter correctly? They way you've set it up right now is that each tween starts at a fixed second value and some tweens are later in the timeline but start before previous tweens (this isn't bad, but if it's not what you want it will not look right). With "-=0.5" you can have a animation start 0.5 seconds before the previous tween ends and with "+=0.5" you can have a tween start 0.5 seconds after the previous tween ends.

 

See below:

 .to("#image-2 .dimmer", {
    "--gradient-alpha": 0
  }, 1) // Starts at 1 second of the timeline 
  .to("#detail-image-1", {
    y: "50vh"
  }, 0.5) // Starts at 0.5 of the time line that is before the previous tween
  .to("#detail-image-2", {
    y: "-30vh"
  }, 0.5); // same a this one.

A minimal demo is in my eyes always necessary, I could probably point you to the solution in an instant if I can see the code in action. Right now it is guessing of what I think the code should do. I would also recommend setting up a start and end in the ScrollTrigger and enable markers: true to see what your ScrollTriggers are doing and if they are where you think they are. 

 

Hope it helps and happy tweening! Otherwise please post a minimal demo.

  • Like 1
Link to comment
Share on other sites

Hi! 

 

First of all, thanks for your super quick response and also the helpful notations! 

Second, sorry for the missing CodePen. Promise that the next question will have one!

Third, actually, after a while I saw that my impression of a first animation with less time at disposition was an impression based on my confusion in understanding the meaning of time (as you say: “1 second” i.g) when having a scrollTrigger timeline (and, in addition with pinned section). As there is actually no time “passing by” but user scroll distance, at least for my feeling.

 

When I started one of the later animations after “1” let’s say at “1.5” the whole animation (or better the scroll) took longer, so the first one seemed faster.

So, yes, all was meant as it actually is. Even if it would have been sure better for understanding ordering the timeline chronologically. (But as I understand it, it is not really relevant for the flow of animations, as the starting times are absolute.)

 

However I am still experimenting and having kind of a hard time to deeper understand the concept of “time” on a scrollTrigger animation.

As said, what is 1 second? What part of the scroll distance does it cover in reality? and so on…

 

Anyhow, great software, great support, thanks very much!

 

Best,

Stefan

Link to comment
Share on other sites

  • Solution

Indeed it is a bit weird to wrap your head around. Normally in GSAP things work based on durations, but with ScrollTrigger that all gets thrown out the window (not really it still matters if you have multiple animations), but in ScrollTrigger the whole animation gets played over the scroll distance you've set. 

 

So lets say we have 10 tweens all of 1 second and we have a ScrollTrigger that animates over 1000px then every animations would take 100px to animate. 1000 / 10 = 100 or 10% of the total scroll duration. When working with ScrollTrigger I usually use logical numbers, so that converting them to ScrollTrigger is easier to grasp. By default tweens in GSAP are 0.5 seconds, just FYI.

 

Hope it helps!

  • Like 3
Link to comment
Share on other sites

However, one could say as an essence of your descriptions: the more animations we have in one scrollTrigger timeline (with default duration 0.5 or whatever) the faster they will animate as they “share” the total amount of “time” (which really isn’t time in seconds) given by the distance of the trigger element.

 

So my first impression wasn’t wrong indeed. Could result complicated doing some reliable math here.

 

Isn’t here something that could say: the tween of element X has to cover XX% of the distance while other animations remain untouched?

And, respectively start at XX%…

 

Just wondering…

Link to comment
Share on other sites

3 minutes ago, Garavani said:

Isn’t here something that could say: the tween of element X has to cover XX% of the distance while other animations remain untouched?

 

No but you could set the end trigger to something like end: "3000px" to increase the distance over which the animation gets played. 

 

Take a look at the following video it is a great explanation on how to go about creating GSAP animations with ScrollTrigger 

 

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