Jump to content
GreenSock

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

Navigating between labels

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

 

as well as playing back an animated visualisation I want to users to be able to jump from point to point.

 

If I set labels in the animation they point to the start of an animation sequence not its end point.

 

While I can use getLabelAfter() etc + an offset that seems a kludge

 

Is there a means to go to a label play back that sequence & stop?

 

I've got a simple codepen derived demo at:

 

http://thisthen.co.uk/gsaptest/

 

 

Mark

Link to comment
Share on other sites

Hello marko,

 

Have you looked into the seek() method:

 

http://api.greensock.com/js/com/greensock/TimelineLite.html#seek()

//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);
 
//jumps to the "myLabel" label
myAnimation.seek("myLabel");

Taken from TimelineMax DOCS:

 

seek()
Jumps to a specific time (or label) without affecting whether or not the instance is paused or reversed.

 

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.

 

Parameters

  • position:* — The position to go to, described in any of the following ways: a numeric value indicates an absolute position, like 3 would be exactly 3 seconds from the beginning of the timeline. A string value can be either a label (i.e. "myLabel") or a relative value using the "+=" or "-=" prefixes like "-=2" (2 seconds before the end of the timeline) or a combination like "myLabel+=2" to indicate 2 seconds after "myLabel".    
  • 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 time parameter.

Returns

  * — self (makes chaining easier)
 

 

Does that help?

Link to comment
Share on other sites

hi

 

thanks for getting back

 

doesn't solve problem that labels are at start of sequences

 

gotoAndStop + an offset works for now, I just hoped for a more elegant solution

 

I guess at some point I can look at having child timelines - but I'm still figuring basic stuff at the moment

 

Mark

Link to comment
Share on other sites

You can use TimelineMax's tweenFromTo() to tween from one label to another label

 

http://api.greensock.com/js/com/greensock/TimelineMax.html#tweenFromTo()

 

timeline.tweenFromTo("march", "feb");

 

or you can use tweenTo("feb") or tweenTo(tl.getLabelAfter()) ... lots of possibilities.

 

Also you could look into using addPause() throughout your timeline

tl.add("march")
tl.to(someMarchThing, 1, {left:200})
tl.addPause()
tl.add("feb")
tl.to(someFebThing, 1, {left:200})
tl.addPause()

if you do tl.play("march") the timeline will start playing at the march label and then stop where the addPause() was inserted.

 

---

 

Thanks for the demo, but its best to link to the demo on CodePen so that we can see what's happening and offer better solutions.

  • Like 2
Link to comment
Share on other sites

hi

 

thanks

 

I will check those out

 

code pen - I couldn't figure out how to add the text plugin

 

Mark

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.

×