Jump to content
Search Community

Zero duration timelines valid?

CraptainRob 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

Hey there. I'm seeing some issues with timelines that happen to have a duration of zero in all versions past 1.10.3. So, for example 1.11.0 has the described problem. The example below works ok...

var test = new TimelineMax();
test.add(function () {
    return console.log("ONE");
});
test.add("label");
test.add(function () {
    return console.log("TWO");
});
test.add("bork");
test.add(function () {
    return console.log("THREE");
});

Change it to this and it will no longer play anything added to the timeline in 1.11.0+...

var test = new TimelineMax({paused: true});
test.add(function () {
    return console.log("ONE");
});
test.add("label");
test.add(function () {
    return console.log("TWO");
});
test.add("bork");
test.add(function () {
    return console.log("THREE");
});
test.play(0);

Adding a duration like below resolves the issue...

var test = new TimelineMax({paused: true});
test.add(function () {
    return console.log("ONE");
});
test.add("label");
test.add(function () {
    return console.log("TWO");
});
test.add("bork");
test.add(function () {
    return console.log("THREE");
}, "+=0.001");
test.play(0);

Did I find a possible bug or just an invalid use case or something?

Link to comment
Share on other sites

It's not really a bug, no - let me explain...

 

You paused the timeline initially, so the playhead is stuck at 0. Fine. You dump some stuff into the timeline, but nothing that actually takes any time. When you play(0), it moves the playhead to 0, suppressing any callbacks/events by default, and starts playing. Callbacks are triggered when the playhead lands on them or moves past them (one or the other of course, not both). So in your case since the playhead never actually moves, it'll only fire the callbacks/events when the playhead lands on them the first time. You didn't tell your play() method not to suppress events, so they were suppressed. The solution is to simply set the suppressEvents parameter to false in your play(0) call:

test.play(0, false);

Make sense now? 

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