Jump to content
GreenSock

savvi

Playing between two points on a timeline

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

Is it possible to play between two points on a timeline?

I'm aware I can use seek to go to a specific point but what I'd like to do is stop as certain point.

 

ie. something like:

 

timeline.playBetween(0.3, 0.9)

 

So my animation would start at 0.3 and end at 0.9 along the duration of the timeline.

Is this possible?

Link to comment
Share on other sites

Hello cocomitte, and welcome to the GreenSock Forums!

 

Have you looked at the GSAP JS pause() method:

 

http://api.greensock.com/js/com/greensock/core/Animation.html#pause()

 

From TimelineLite Docs:

 

Pauses the instance, optionally jumping to a specific time.

 

If you define a time to jump to (the first parameter, which could also be a label for TimelineLite or TimelineMax instances), the playhead moves there immediately and if there are any events/callbacks inbetween where the playhead was and the new time, they will not be triggered because by default suppressEvents (the 2nd parameter) is true. Think of it like picking the needle up on a record player and moving it to a new position before placing it back on the record. If, however, you do not want the events/callbacks suppressed during that initial move, simply set the suppressEvents parameter to false.

// pauses wherever the playhead currently is:
myAnimation.pause();
 
// jumps to exactly 2-seconds into the animation and then pauses:
myAnimation.pause(2);
 
// jumps to exactly 2-seconds into the animation and pauses but 
// doesn't suppress events during the initial move:
myAnimation.pause(2, false);

Parameters

  • atTime:* (default = null) — The time (or label for TimelineLite/TimelineMax instances) that the instance should jump to before pausing (if none is defined, it will pause wherever the playhead is currently located).    
  • suppressEvents:Boolean (default = true) — If true (the default), no events or callbacks will be triggered when the playhead moves to the new position defined in the atTime parameter.

Returns

* — self (makes chaining easier)

 

If you need specific help relating to your code, it would be best to setup a codepen demo example so we can see your code in action in a live editable environment.

 

Here is a cool video tut by GreenSock on How to create a codepen example demo.

 

Hope this helps?

  • Like 1
Link to comment
Share on other sites

in addition, if your timeline is  a TimelineMax you can use the tweenFromTo() method like so

//twee from time of 0.3 to 0.9
timeline.tweenFromTo(0.3, 0.9);

//add an ease and callback
timeline.tweenFromTo(0.3, 0.6, {ease:Bounce.easeOut, onComplete:completeHandler});

//you can also use labels
timeline.tweenFromTo("section1", "section2");

tweenFromTo() docs

  • Like 2
Link to comment
Share on other sites

Awesome, thanks Carl, I was just looking for that too :)

Link to comment
Share on other sites

thanks guys

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