Jump to content
Search Community

Is there a way to find out the yoyo direction?

MarcoBarbosa test
Moderator Tag

Go to solution Solved by Diaco,

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

Consider a repetable yoyo tween:

TweenMax.fromTo(
  $el, 
  2,
  {
    y: 0
  },
  {
    y: 3,
    repeat: -1, 
    yoyo: true, 
    ease: Power3.easeOut,
    onRepeat: function() {
    // How do I find out this is going backwards?
  }
);

The docs doesn't specify how to get it's direction. I know that reversed() doesn't get afffected by yoyo as stated:

 

This value is not affected byyoyo repeats (TweenMax and TimelineMax only) and it does not take into account the reversed state of anscestor timelines.

 

 

So how can I find out if it's yoyo'ing or not? :o

 

Link to comment
Share on other sites

Btw I've solved it by having an internal variable:

 

var i = 0;
TweenMax.fromTo(
  $el, 
  2,
  {
    y: 0
  },
  {
    y: 3,
    repeat: -1, 
    yoyo: true, 
    ease: Power3.easeOut,
    onRepeat: function() {
    i++;


    if (i % 2 == 1) {
      // Going backwards...
    }
  }
);

I would still like to know if there is anything in the core that supports this check.

  • Like 1
Link to comment
Share on other sites

Great answers guys.

 

Marco, there is nothing baked into GSAP to give you the direction of the yoyo-iteration. And as you have discovered, a yoyo-ed tween is never truly reversed().

 

I think you may find this thread: http://greensock.com/forums/topic/9446-how-to-find-out-whether-animation-is-currently-playing-in-reverse-with-yoyotrue/interesting at discusses some of the complexities of assessing the "direction" of the yoyo iteration especially when you consider that a yoyo-ed tween may be in a timeline that is reversed and other tricky things.

 

I just made a CodePen that utilizes Jack's formula for detecting if a yoyo-ed tween is appearing to play backwards

 

http://codepen.io/GreenSock/pen/nmALB?editors=001

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