Jump to content
Search Community

Setting visibility to visible goes faster than setting opacity to 0.

astanar test
Moderator Tag

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

hey, I'm trying to make a section disappear on click and another one show up. Setting the opacity to 0 goes smoothly but then the visibility of section2 goes super fast while I'd like it to be as slow as the first one.

 

var section1 = document.getElementById("section1");
var section2 = document.getElementById("section2");

document.addEventListener("click", function(){
var tl = new TimelineLite();
tl.add( TweenLite.to(section1, 1, {opacity:0 , ease: Power0.easeNone}) );
tl.add( TweenLite.to(section2, 1, {visibility:'visible', ease: Power0.easeNone}) );
    
});

 

my css is currently this:

 

selector {
    overflow-y: hidden;
}

#section2 {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    visibility: hidden;
    
}

 

Sorry if this seem stupid I'm new to all this.

 

thanks

Link to comment
Share on other sites

Hi @astanar,

 

Welcome to the forum and thanks for joining Club GreenSock.

 

You can't tween visibility as it's a binary setting. (visible/hidden) There's nothing for GSAP to calculate and tween. Opacity can be animated between 0 and 1. 

 

I'd recommend the best of both worlds by using autoAlpha. That property is a combination of opacity and visibility. Once the opacity of autoAlpha tweens hits 0, the visibility property will be set to hidden.

 

More info:

https://greensock.com/docs/Plugins/CSSPlugin#autoAlpha

 

Hopefully that helps. Happy tweening.

:)

 

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