Jump to content
Search Community

Adding a delay that doesn't change with Timescale

Fakebook test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I'm curious how I can create a delay that is not affected by the timeScale property. For instance, I'd like a variable that changes the overall speed of each animation, but not the amount of time that it pauses for. In my example, the timeSpeed constant could go from .5 to 3.

 

Is there an easy way to tell timeScale to ignore delays?

const timeSpeed = .5;
const pauseTime = 1;

const tl = new TimelineMax({repeat: -1});
tl.timeScale( timeSpeed );

tl.to("div", .5, {x: "+=100", y: "+=100"})
  .to("div", .5, {x: "-=200", delay: pauseTime})
  .to("div", .5, {x: "+=100", y: "-=100", delay: pauseTime})
  .to("div", 0, {delay: pauseTime})
;

 

See the Pen WJdpqo?editors=0110 by anon (@anon) on CodePen

Link to comment
Share on other sites

Adding delay to tweens using delay method does not get affected by the TimeScale but it seems like it does get affected by globalTimeScale or timeScale of parent timeline. So you will need to set timescale on individual tweens instead of timeline.

 

See the Pen aGEWQg?editors=0010 by Sahil89 (@Sahil89) on CodePen

 

if you want to change globalTimeScale or parent timeline's timeScale and want the tweens to keep delay then you will need to update delay and multiply it with timeScale.

  • Like 2
Link to comment
Share on other sites

Yep, exactly. If you change the timeScale of a timeline, it would of course affect all of its children (including delays) because the parent playhead is literally moving at a different pace. It would be really weird if the delays weren't affected because that would totally change their placement in the timeline (their startTime()) in relation to each other. 

 

That would be sorta like if you moved a <div> to new coordinates, but you only wanted its children to move without factoring in their padding or margin values. See what I mean? 

 

But yeah, you can totally get the effect you want, you'd just need to adjust each of the delays or startTimes accordingly, as @Sahil mentioned. 

 

Here's a function that might be helpful:

function timeScaleSkipDelays(tl, timeScale) {
    var children = tl.getChildren(),
        ratio = timeScale / tl.timeScale(),
        i;
    for (i = 0; i < children.length; i++) {
        children[i].delay( children[i].delay() * ratio );
    }
    tl.timeScale(timeScale);
}

 

Then you can just use that function to change the timeScale and it'll automatically alter the delays to compensate. Is that what you're looking for? 

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