Jump to content
Search Community

How to make a hidden element visable

AssaSSAins test
Moderator Tag

Recommended Posts

I have a div tag as display: none in my css. I have a button element which has an event listener. When clicked, I would like it to make the div tag visible. I have tried using opacity and that did not work. Then, I tried some more. Would I have to use something else then gsap.to, is that the issue? If so, please let me know what to use. Thanks.

 

function check() {
  console.log("hey");
  gsap.to(".gra", { autoAlpha: 1 });
}

 

Link to comment
Share on other sites

Hey @AssaSSAins,

 

Instead of display: none you can use visibility: hidden in your CSS. And then ...

 

 

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.

 

//fade out and set visibility:hidden
gsap.to(element, {
    duration: 2, 
    autoAlpha: 0
});

//in 2 seconds, fade back in with visibility:visible
gsap.to(element, {duration: 2, autoAlpha: 1, delay: 2});

 

Happy tweening ...

Mikel

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