Jump to content
Search Community

Repeat animation uneven times

ludo test
Moderator Tag

Recommended Posts

Hi, 

 

New to the forums, but awesome community you have going on. 

 

Just started dabbling in GSAP, and I am sure this is a quite easy question - but having some issues with trying to achieve the effect I am after...

I am creating a banner, which should animate for X number of repeats (elements sliding in, then out). The final iteration I want the elements to only slide in, and not slide out. 

 

I have three timelines: 

1. Intro - managing the sliding in of elements

2. Outro - managing the sliding out of elements

3. Master - chaining these two together

 

I tried using the onComplete   callback function to run the intro() a final time before completing the iterations.
However, when doing so the whole animation somehow bugs out and elements appear and reappear randomly. 

 

Another bonus effect which I am after (not sure if possible?) is to run the full animation for a maximum of 30 seconds, adjusting the number of repeats accordingly. 

 

Anyone has some good input on this one? 

 

Thanks!

See the Pen OJaLOwZ by codepenuser9 (@codepenuser9) on CodePen

Link to comment
Share on other sites

Hi @Rodrigo

 

Thank you very much for the input!

I did investigate Yoyo, however the image animation needs to go out to the left rather than right otherwise it would have been the perfect option :)

 

I believe I managed to solve it by returning a new timeline from each function call, rather than setting global vars, and modifying the onComplete function like so (initializing a new copy of the intro() timeline, passing paused:true and starting it through .play() function). 

 

...

onComplete: function () {
    intro({ paused: true, delay: "2" }).play();
},
});

 

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