我试图让我的FAQ容器成为动态/响应式,但在正确使用它时遇到了一些麻烦。在div点击动态切换动态(或“自动”)高度
目前,我可以打开容器,但如果再次点击它,它不会收回(或关闭)。以下是我有:
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');
});
});
这是上面的代码中的一个FULL DEMO ...
另一种方法我试过是这样的:
$('.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);
}
});
然而,正如你在这里所看到的,这是基于“固定”高度,而不是将其设置为更具动态性/响应性的方式......
下面是对这个这个其他替代
我想如果可以使用第一种方法,但似乎无法得到的股利收备份...
任何帮助一个DEMO将不胜感激!
您正在使用jQuery,那么为什么不使用jQuery UI手风琴呢? https://jqueryui.com/accordion/或引导程序崩溃https://v4-alpha.getbootstrap.com/components/collapse/#example – gforce301