Jump to content
Search Community

Adding repeat functionality after the tween is declared.

Osiris test
Moderator Tag

Recommended Posts

Hello, can anyone explain to me, why the following is not working (repeat needs to be added when the tween is already declared)? 

var myTween = gsap.to(object, {duration: 1, opacity: 0, paused: true})
myTween["vars"]["repeat"] = -1;
myTween.play();

I believe the above approach is valid, because when i write the following just before i call myTween.play()

myTween["vars"]["onComplete"] = function(){console.log("completed")}

i can see the console output "completed", when the animation is complete. I don't understand, why myTween["vars]["repeat] = -1 does not do anything. If i call console.log(myTween) after the "repeat" thing is declared, i can see it's added in the vars object already.   

Link to comment
Share on other sites

Changing repeat needs to be done internally, so that won't work. You should use the repeat method.

https://greensock.com/docs/v3/GSAP/Tween/repeat()

 

16 minutes ago, Osiris said:

I believe the above approach is valid, because when i write the following just before i call myTween.play()



myTween["vars"]["onComplete"] = function(){console.log("completed")}

 

That's a little different than changing the repeat logic, as it's just calling what's on the vars object. A cleaner way to do that is with the eventCallback method.

https://greensock.com/docs/v3/GSAP/Tween/eventCallback()

 

Generally, messing with the vars object isn't going to change anything unless you invalidate the animation.

 

Also note that those methods are also available on timelines. The full docs for Tweens and Timelines can be found here.

https://greensock.com/docs/v3/GSAP/Tween

https://greensock.com/docs/v3/GSAP/Timeline

 

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