Jump to content
Search Community

Repeat yoyo with some pause/interval

deb test
Moderator Tag

Go to solution Solved by kez1304,

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

var element = document.getElementById("pilot");

var tl = new TimelineMax();

tl.fromTo(element, 0.1, {
  x:"+=20"
}, {
  x:"-=20",
  yoyo:true,
  repeat:10
})
.repeatDelay(2)
.repeat(-1);

This solution switches your TweenMax for TimelineMax.

 

I'm not sure if there's a way to do it purely with TweenMax, as it requires adding a repeat onto the tween itself (the 10, for the shaking), and then a repeat for the entire tween animation (the -1, infinite repeat), and finally a repeat delay onto the entire tween's infinite repeat (the 2, for a 2 second delay.

 

I also switched the two tweens from two to's, to a fromTo tween, as it just made more sense to do so in this instance.

 

Oh, and I added overflow: hidden to your '.wrapper' class in your CSS, to get rid of the annoying scrollbar appearing at the bottom of the page, but that's just me.

  • Like 1
Link to comment
Share on other sites

Great job kez1304,

 

On top of the correct advice given, I'd like to add that you could pass the repeat and repeat delay into the Timeline's object.

var element = document.getElementById("pilot");

var tl = new TimelineMax({repeat:-1, repeatDelay:2});

tl.fromTo(element, 0.1, {
 x:"+=20"
}, {
 x:"-=20",
 yoyo:true,
 repeat:10
})
  • 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...