Jump to content
Search Community

How to start timeline from opacity: 0 every repeat?

Dima34

Recommended Posts

Posted

Hi all! 
I know about fromTo, but it`s not working as i expect. 
I have a code 

let coinTimeline = gsap.timeline();
                        
coinTimeline.to(movableCoin, {
    duration: 3,
    motionPath: {
        path: bezierToMove,
        autoRotate: true,
        align: movableCoin,
        alignOrigin: [0.5, 0.5]
    },
    repeat: -1,
    ease: "power1.inOut"
});

coinTimeline.fromTo(movableCoin, {opacity: 0}, {
    duration: 1,
    opacity: 1
}, 0);        

And the opacity changing is only in first repeat of animation. Each next time the coin starts from opacity 1.

image.gif.6f05a25776f7388d24c5bd2911c52113.gif

 

How can I fix that and start it from 0 every time? 


 

Posted

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen.

that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Posted
16 hours ago, GSAP Helper said:

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

 

that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Created one

See the Pen MWNgMNG?editors=1000 by Dima34_1 (@Dima34_1) on CodePen.

Posted

Hi @Dima34,

I'm not sure, about the animation duration but you can try below code.

 

 

    let coinTimeline = gsap.timeline();

    coinTimeline.to(movableCoin, {
      duration: 3,
      motionPath: {
        path: bezierToMove,
        autoRotate: true,
        align: movableCoin,
        alignOrigin: [0.5, 0.5]
      },
      opacity: 1,
      repeat: -1,
      ease: "power1.inOut"
    });

    // coinTimeline.fromTo(
    //   movableCoin,
    //   { opacity: 0 },
    //   {
    //     duration: 1,
    //     opacity: 1
    //   },
    // );

 

Posted

Hi,

 

The issue is that your opacity instance does not repeat like the one with the MotionPath does.

 

This seems to work the way you intend:

let coinTimeline = gsap.timeline();

coinTimeline.to(movableCoin, {
  duration: 3,
  motionPath: {
    path: bezierToMove,
    autoRotate: true,
    align: movableCoin,
    alignOrigin: [0.5, 0.5]
  },
  repeat: -1,
  ease: "power1.inOut"
});

coinTimeline.fromTo(
  movableCoin,
  { opacity: 0 },
  {
    duration: 1,
    opacity: 1,
    repeat: -1,
    repeatDelay: 2,
  },
  0
);

Since the animation with the motion path is longer than the opacity animation, I added a repeatDelay of 2 seconds so they both repeat at the same time.

 

Hopefully this helps

Happy Tweening!

  • Like 1

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