Jump to content
Search Community

problems with addPause

trsh 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 have code that looks something like this  .

The problem is, that addPause overwrites previous added addPause (with same time), and the callback is gone.

Any tips how to make this work? How can I get both callbacks in same time?

 

P.S. I cant create a Master function, with sub-functions in my case :/, my real project code is very dynamic.

See the Pen XjgVWN by anon (@anon) on CodePen

Link to comment
Share on other sites

Thanks for the demo. Its a tricky scenario. It could be argued that it doesn't ever make sense to have multiple addPause() calls at the same time.  I think your issue might more deeply revolve around how should multiple callbacks that share the same time as an addPause() be handled.

 

I found that adding the callbacks separately first and at the same time() as the addPause() gives the results you probably want:

 

rootTL.add(function() {
  console.log("1");
}, 2)


rootTL.add(function() {
  console.log("2");
}, 2)


rootTL.addPause(2)

http://codepen.io/GreenSock/pen/dpRQBk?editors=0011

 

But if you switch the order of operations around (addPause() first) the callbacks won't fire.

 

rootTL.addPause(2);


//these functions will not fire
rootTL.add(function() {
  console.log("1");
}, 2)


rootTL.add(function() {
  console.log("2");
}, 2)

http://codepen.io/GreenSock/pen/KgqbKP?editors=0011

 

We will have to consider how feasible it is to make things "work" the way you expect. Please stand by.

  • Like 3
Link to comment
Share on other sites

Thanks. For now I will go with your first example. 

I'm also not sure, if addPause should be added multiple times in same spot, but in the same time that's for what word "add" stands for. Should be renamed to setPause (or something like that) otherwise.

Link to comment
Share on other sites

I can't seem to find any odd behavior here. It seems like it's doing exactly what I'd expect. In fact, a lot of work went into making it function this way :) Several versions back, there was a bug report that complained that the addPause() wasn't stopping things deeply enough, like other callbacks that were added at that time (but technically placed there after the pause was in place). So things are firing normally, then as soon as it hits the pause, it pauses all execution. 

 

I'm also having a hard time understanding why multiple pauses would be placed at the same spot on purpose, and expected to fire (all of them). Things have to happen in a particular order. So if a pause is encountered, were you thinking that it should still allow further processing and firing of other callbacks after that pause? And what would happen if it hits the first pause(), and then later play() is called? Would it encounter that 2nd (and 3rd...) pause and immediately stop, meaning you'd have to call play() multiple times to get it to work? While I can see how one could argue that's desirable in some cases, I'm pretty sure we'd also get complaints from another contingency who'd argue it's illogical to behave that way. 

 

I don't really understand your real-world use case, but maybe you could just use a single function that manages a queue of functions that you can add to anytime. It shouldn't be terribly difficult (though again, I don't really know the context so I could be wrong). 

  • Like 3
Link to comment
Share on other sites

I can't seem to find any odd behavior here. It seems like it's doing exactly what I'd expect. In fact, a lot of work went into making it function this way :) Several versions back, there was a bug report that complained that the addPause() wasn't stopping things deeply enough, like other callbacks that were added at that time (but technically placed there after the pause was in place). So things are firing normally, then as soon as it hits the pause, it pauses all execution. 

 

I'm also having a hard time understanding why multiple pauses would be placed at the same spot on purpose, and expected to fire (all of them). Things have to happen in a particular order. So if a pause is encountered, were you thinking that it should still allow further processing and firing of other callbacks after that pause? And what would happen if it hits the first pause(), and then later play() is called? Would it encounter that 2nd (and 3rd...) pause and immediately stop, meaning you'd have to call play() multiple times to get it to work? While I can see how one could argue that's desirable in some cases, I'm pretty sure we'd also get complaints from another contingency who'd argue it's illogical to behave that way. 

 

I don't really understand your real-world use case, but maybe you could just use a single function that manages a queue of functions that you can add to anytime. It shouldn't be terribly difficult (though again, I don't really know the context so I could be wrong). 

OK, OK!

Link to comment
Share on other sites

Hello buddy!

 

If you're using TimelineMax or TimelineLite and you want add little delay or similar to pause you can use this simple trick.
 

var tl = new TimelineMax();

tl.to("#object", 1, {alpha: 1})
  .to("#object", 1, {alpha: 0, delay: 1}); //this will add 1 second delay before alpha 0

Hope it helps!

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