Jump to content
Search Community

Most efficient way of setting timeline playhead?

martis 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

Hi,

 

In terms of performance I don't know, my assumption is that there wouldn't be any noticeable effects.

 

The main key in this subject is what your scenario is. Is your timeline playing/reversing or is it paused?

 

time() and seek() won't modify the current state of your timeline, if it's paused will remain paused, if is going backwards, after setting the playhead in the indicated position it'll keep going backwards, while play() and reverse() will set the direction starting at a particular time/label.

 

Also you can look into tweenTo() and tweenFromTo():

 

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

 

Those are very nifty methods but they have their up and downsides, like I said it depends of what you're after, perhaps a codepen could help us get a better grasp of what you're after.

 

Best,

Rodrigo.

Link to comment
Share on other sites

If you just need to jump the playhead to a specific time, then using timeline.time() is perfectly fine.

 

time() is handy if you just want to move to a numeric time and don't want to have to adjust for repeats (if you have any). time() does not suppress events/callbacks by default. It's also a getter for the tween/timelines current time.

 

seek() lets you jump to a numeric time ( .seek(3) ), relative time ( .seek("+=3") ), or a label ( .seek("mylabel") ). seek() suppresses events/callbacks by default.

 

In reality, the differences between the playhead moving functions wouldn't be large enough to be worth measuring, so I wouldn't worry about it too much. But, I guess if you want to boil down to it, both time() and seek() eventually call totalTime() to adjust the playhead, so if you have a numeric time to jump to, you might save a couple of CPU cycles using totalTime() directly. If you are using repeats you may want to stick with time() though.

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