Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Acmafali

Play and rewind to specific points in 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

Hi,

 

I would like to know how to play to specific points in the timeline with one button which will then pause once that point is reached until the play button is pressed again. Also I would like to know how to rewind to specific points in the timeline which will pause to that point until its pressed again. So i will only have 2 buttons in total which is rewind to previous check point and forward to next check point.

 

I know this seems really obvious but the logic behind this is actually confusing me.

 

Thanks.

Link to comment
Share on other sites

Hello Acmafali and Welcome to the GreenSock Forum!

 

For that you would use labels so you can jump to a specific point in the timeline like in this GreenSock codepen example:

 

See the Pen plsng by GreenSock (@GreenSock) on CodePen

 

Check out this codepen by GreenSock on how to control playback:

 

See the Pen sLavi by GreenSock (@GreenSock) on CodePen

 

Here are some video tuts by GreenSock to help you understand how to create tweens and timelines to animate.

 

How to sequence animations in GSAP:

 

 
How to use the position parameter:
 
 
And the GSAP Jump Start page to learn:
 
 
And you can find more info on the GSAP API Docs:
 
 
You can also use the seek() method:
 
//jumps to exactly 2 seconds
myAnimation.seek(2);

//jumps to exactly 2 seconds but doesn't suppress events during the initial move:
myAnimation.seek(2, false);
If you are still having issues please create a codepen demo example so we can see your code in context to better help you:
 
 
Hope this helps :)
  • Like 3
Link to comment
Share on other sites

Hi Acmafali  :)

 

In addition to Jonathan's excellent advice and links, I think you're asking about playing certain sections of a timeline for testing purposes. When I'm making a longer animation and only want to test small sections of it, I use a fromTo() between testing labels on the timeline. These labels can be moved around as needed. Then you just have to add a button or two to play() and reverse() it while you're working.

 

Your button(s) would then work like this:

document.getElementById("yourButton").onclick = function() {
tl.tweenFromTo("startTest", "endTest"); // those are the labels added to the timeline
}

Here's a simple CodePen to show you how this works.

See the Pen EKZjpo by PointC (@PointC) on CodePen

 

Hopefully that helps a bit.

 

Happy tweening.

:)

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