Jump to content
Search Community

Animation with 3 iterations, Add different animation on third iteration

Adel Kamel test
Moderator Tag

Recommended Posts

Hi,

 

You can use a call() method instead of the to method and check the current iteration of the timeline:

const timeline = gsap.timeline({ repeat: 2, repeatDelay: 2 });

timeline
  .to(visual, { left: 0, opacity: 1, duration: 1, delay: 0.5 })
  .to(visual, { left: -277, opacity: 0, duration: 1, delay: 4 })
  .to(square, { opacity: 1, stagger: 1 })
  .call(() => {
  if (timeline.iteration() < 3) {
    gsap.to(square, {
      delay: 2,
      opacity: 0,
      duration: 0.2
    });
  }
})
  .to(
  {},
  {
    delay: 2,
    duration: 0.2
  }
);

Here is a fork of your codepen:

See the Pen BaGmVpd by GreenSock (@GreenSock) on CodePen

 

Finally is worth noticing that you are using a version of GSAP that is a bit outdated: 3.10.4, we're currently at 3.12.2 which should work in the same way, so I would recommend that you update it.

 

Hopefully this helps.

Happy Tweening!

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