Jump to content
Search Community

Opacity not changing

jsring test
Moderator Tag

Go to solution Solved by Jonathan,

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 example codepen I have two divs overlapping each other. During the tweenLite activity the first div fades out and at the end needs to fade back in. It appears that it's opacity seems to remain at 0. In otherwords, the div with the button should reappear.

 

Does anyone have a solution?

See the Pen vapCs by jsring (@jsring) on CodePen

Link to comment
Share on other sites

  • Solution

Hello jsring, and Welcome to the GreenSock Forum!

 

The best thing to do is use autoAlpha in this case

 

Example:

See the Pen Kqpwd by jonathan (@jonathan) on CodePen

 

You wont need to set display:none when you set opacity to 0 

TweenLite.set(".hidingText", {autoAlpha: 0});
    
function secret(){
  console.log("Revealing Secret");
  var reveal = new TimelineLite();
  reveal.to(".revealText",  1.4, {autoAlpha: 0, ease:Power4.easeOut}, 0)
  .to(".hidingText", 1, {autoAlpha: 1, ease:Power4.easeInOut}, -0.4)
  .to(".hidingText", 1.4, {autoAlpha: 0, ease:Power4.easeInOut}, 1)
  .to(".revealText", 1, {autoAlpha: 1, ease:Power4.easInOut}, -0.4)
}

:

Taken from the CSSPlugin Docs:

 

autoAlpha

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.

// autoAlpha examples

//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});

:

http://greensock.com/docs/#/HTML5/Plugins/CSSPlugin/

 

If you really need to set display:none after the tween animates opacity to zero (0) .. than you could use an onComplete callback and set display:none there.

 

Does that help?

Link to comment
Share on other sites

Yes, Jonathan's suggestion to use autoAlpha is great for this.

 

I just want to make a little note, If you tween display to  "none", the hidden property will be set at the end of the animation.

 

Here is a basic example. Notice the circle disappears when it reaches x:400

TweenLite.to(".circle", 1, {x:400, display:"none"})

http://codepen.io/anon/pen/LfldD

 

Also note that since changing the display value effects document flow, it is usually preferred to us autoAlpha as visibility does not impact flow (which is why the text shifts in the demo above)

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