I assume that you want to use visibility: hidden instead of displaying: none so that you see empty space.
If so, fadeIn () and fadeOut () will not work for you because it disables the display after it disappears.
Instead, use jQuery animate () to animate the opacity, and then add visibility: hidden / visible in the callback.
This is how I will do it with jQuery.
$('#a-id').click( if( $('#div-id').css('visibility') == 'hidden'){ $('#div-id').animate({opacity: 1}, 'fast', function(){ $('#div-id').css('visibility', 'visible'); }); }else{ $('#div-id').animate({opacity: 0}, 'fast', function(){ $('#div-id').css('visibility', 'hidden'); } );
I am sure there is a better way to do this, but it works without afaik problems.
source share