Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Jquery fade/toggle only works on first click… Re: Jquery fade/toggle only works on first click…

#83467
Mottie
Member

Hmm, ok try this:

var ht = $('#panel').height();
$('#panel').height(0);
$('#info').hide();

$(".btn-slide").click(function() {
var d = $('#info').is(':hidden');
if (!d) { $('#info').fadeOut(200); }
$('#panel').animate({ height: (d) ? ht : 0 }, 500, function(){
$('#info')[(d) ? 'fadeIn' : 'fadeOut']();
});
$(this).toggleClass("active");
return false;
});

I changed it from slideToggle because adding a callback seemed to fast-forward the slidedown animation.