Jump to content


Using tweenTo() to loop forwards only

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 use tweenTo on a TimelineMax instance to loop forwards until it hits a specified time?


So calling tweenTo(2) while the the playhead is at 5 seconds on a 10 second animation would first play to the end before looping back around and stopping at the specified .


I did come across this but it talks about the old flash version and frames: http://greensock.com/forums/topic/2407-tween-frames-forward-only/


Any point in the right direction appreciated. I'll try and look into writing a plugin for it.

Link to comment
Share on other sites

I doubt you'd need a special plugin or anything. You should be able to just use a simple function like this: 

function tweenForwardTo(tl, timeOrLabel, vars) {
    if (typeof(timeOrLabel) === "string") {
        timeOrLabel = tl.getLabelTime(timeOrLabel); 
    if (timeOrLabel < tl.time()) {
        var sequence = new TimelineLite();
        return sequence.add(tl.tweenTo(tl.duration(), vars)).add(tl.tweenFromTo(0, timeOrLabel, vars));
    return tl.tweenTo(timeOrLabel, vars);

Then you can just call tweenForwardTo(yourTimeline, 2). I haven't tested that (in a bit of a rush), but in theory it should work ;) 

Is that what you're looking for? 
  • 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.