I'm trying to make my FAQ container(s) be dynamic/responsive but am having some trouble getting it to work just right.
At the moment, I can open the container but it doesn't retract (or close) if clicked again. Here is what I have:
JS:
$('.faq_container').on('click', function() {
$(this).find('.faq_up-arrow, .faq_down-arrow').toggle();
$(this).animate({
height: $('.faq_container').get(0).scrollHeight
}, 250, function() {
$(this).height('auto');
});
});
Here is a FULL DEMO of above snippet...
An alternative approach I've tried is this:
$('.faq_container').on('click', function () {
$(this).find('.faq_up-arrow, .faq_down-arrow').toggle();
if ( $(this).height() != 40) {
$(this).animate( { height : 40 }, 250);
} else {
$(this).animate( { height : 400 }, 250);
}
});
However, as you can see here, this is based on a "fixed" height rather than setting it to a more dynamic/responsive way...
Here is a DEMO for this other alternative
I'd like to use the first approach if possible, but can't seem to get the div to close back up...
Any help on this would be greatly appreciated!