Jump to content
Search Community

Play a percentage of a Timeline?

flysi3000 test
Moderator Tag

Go to solution Solved by GreenSock,

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

I might be just having a brain fart, but is there a simple way to tell a TimelineLite instance to play, and stop when it gets to x% of it's total duration?


Just for context, I have gauge that's an svg, and I'm using drawSVG to animate all of the elements of a specific class name to indicate how full the gauge is. So if it were, say 75% full, I'd only want the Timeline to animate to 75% of the total. In the attached codepen example, only only some of the rays on that icon would animate.


There might be a way better way to do this - I'm very open to suggestions!


See the Pen NqLLBx by flysi3000 (@flysi3000) on CodePen

Link to comment
Share on other sites

  • Solution

Absolutely; there are several ways to do this....


1) If you're using TimelineMax, you can use its tweenTo() method:


tl.tweenTo( tl.duration() * 0.7 ); //tween to 70% progress


What's kinda cool is that you can even apply easing to that tween if you want, and/or add an onComplete or whatever - under the hood all it's doing is pausing the timeline and creating a tween of the timeline's "time" property, using a linear ease by default but you can easily customize it by adding a vars object:


tl.tweenTo( tl.duration() * 0.7, {ease:Power3.easeInOut, onComplete:yourFunction});


2) You could use addPause() to insert a pause() at that particular spot:


tl.addPause( tl.duration() * 0.7 );


There are actually a bunch of other ways you could accomplish this too, but I don't want to overwhelm you ;)


Does this help?

  • 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.
  • Create New...