I’m trying to use jQuery’s slideToggle function to show or hide a panel which has been hidden using CSS position, rather than display:none (as this causes issues with a Google Map in one of my panels).
At the moment I’m just hiding and showing the panels like so, but some animation would be nice:
$('.panel').addClass('hidden');
$('.head > span').addClass('closed');
$('.head').click(function() {
$(this).next('.panel').toggleClass('hidden');
$(this).children('span').toggleClass('open');
});
Any ideas?
slideToggle animates height of the element in question apart from visibility. Not sure how exactly you have used CSS position to show/hide your panels. Based on that you have to build you own animation using animate function. Another quick way could be to
For showing element:
Hide the element (using jquery hide())
Apply your class to show element
(i.e. to adjust its position)
Now apply slideDown
For hiding content:
Apply slideUp – use callback function to do steps 2 & 3
Apply your class to hide element
(i.e. to adjust its position outside window)
Show the element (using jquery show())
Edit: Illustrative code goes below (assuming that ‘hidden’ classes will do CSS positioning to hide the element):