Jump to content


Reset opacity before each repetition of looping animation

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

In the attached CodePen, I'm struggling with the Ripple animation that starts on line 28. I want the ripples to start out at 0% opacity, fade in as they scale up, and then go back to 0% before the start of a new repetition cycle. I use the following before starting the timeline:


TweenMax.set(".ripple", {opacity:0});


However it's obviously not part of the timeline itself, so it's not resetting the opacity before each cycle. This, at least I assume, is why I always see the ripples fixed at their original size after the initial sequence/repetition.


I'm guessing I either need to specify this element's property somehow in the object that initializes with the new TimelineMax({repeat:-1}) on line 28, or make it part of the timeline at the end? I've also noticed strange behavior when I apply overlap values, such as "-=.3", at the end of blocks when that value is greater than the duration of the animation itself. But I don't think that's happening here, is it?


Thanks for the help!

See the Pen gozKNN by Nathan_James (@Nathan_James) on CodePen

Link to comment
Share on other sites

Figured it out! I have to use autoAlpha instead of opacity. Can anyone tell me why though? What exactly is the difference between the two?


const rippleTl = new TimelineMax({repeat:-1});
TweenMax.set(".ripple", {autoAlpha:0});

  .fromTo("#centerCircle", 1, {scale:5, transformOrigin: origin}, {scale: 0, transformOrigin: origin, ease: Circ.easeOut})
  .staggerTo(".ripple", 1.5, {scale: 5, autoAlpha: .8, transformOrigin: origin}, .4, "-=.3")
  .staggerTo(".ripple", 1, {opacity: 0, transformOrigin: origin}, .6, "-=1.5");


  • Like 1
Link to comment
Share on other sites

Hi @magyarn,


e.g. Jonathan unlocks the secret here: 



Identical to opacity except that when the value hits 0 the visibility property will be set to "hidden" in order to improve browser rendering performance and prevent clicks/interactivity on the target. When the value is anything other than 0, visibility will be set to "inherit". It is not set to "visible" in order to honor inheritance (imagine the parent element is hidden - setting the child to visible explicitly would cause it to appear when that's probably not what was intended). And for convenience, if the element's visibility is initially set to "hidden" and opacity is 1, it will assume opacity should also start at 0. This makes it simple to start things out on your page as invisible (set your css visibility:hidden) and then fade them in whenever you want. 

//fade out and set visibility:hidden
TweenLite.to(element, 2, {autoAlpha:0});
//in 2 seconds, fade back in with visibility:visible
TweenLite.to(element, 2, {autoAlpha:1, delay:2});


Happy tweening ...


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