Jump to content
Search Community

TweenTo Not looping forward

jollygreen 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

Hello -

 

On the code pen below, when we click the Stop button, the pink box stops on one of the boxes on top.  Nevertheless, the pink box loops backward instead of forward (ie, the pink box moves in opposite direction after clicking the stop button).  How could I make the pink box to loop forward?  I'd appreciate the help.

 

See the Pen GzLdvJ by jollygreen10 (@jollygreen10) on CodePen

 


<script async src="https://static.codepen.io/assets/embed/ei.js"></script>

 

 

See the Pen GzLdvJ by jollygreen10 (@jollygreen10) on CodePen

Link to comment
Share on other sites

You could use a proxy object and a modulus operator to accomplish this:

See the Pen 4eda4336ac74b492e407196d693b3f85 by GreenSock (@GreenSock) on CodePen

 

Here's the function I wrote for you that should make it relatively easy: 

function tweenForwardTo(label) {
  var currentTime = timeline.time(),
      futureTime = timeline.getLabelTime(label),
      duration = timeline.duration(),
      proxy = {time:currentTime};
  if (futureTime < currentTime) {
    futureTime += duration;
  }
  timeline.pause();
  return TweenLite.to(proxy, futureTime - currentTime, {time:futureTime, ease:Linear.easeNone, onUpdate:function() {
    timeline.time(proxy.time % duration);
  }});
}

 

Does that help?

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