我正在使用jquery扩展父点击高度,基于绝对定位手风琴的高度。在这种情况下,它必须是绝对的定位。获取高度的手风琴打开状态,同时关闭
每个手风琴按钮都有自己的功能,父母的高度将是手风琴的标题(按钮)+内容,并且将根据手风琴的哪一部分打开而改变。
的问题是,以动态地得到正确的高度,我需要知道的内容的大小时处于打开状态作为默认的文档加载关闭状态height:0;
$('.button').click(function(){
var accordionHeight = $('.accordion-content').height(); //default closed state, height:0;
$('.parent').height(accordionHeight + $('.accordion-title').height());
});
有什么办法确定手风琴内容在开启状态下的高度,而不将默认状态设为开启状态?
如果您需要更多信息,请让我知道。
编辑:一些更多的信息
想象有两个孩子的父母DIV。手风琴是一个孩子,而另一个手风琴的高度始终与所有州的手风琴师相同。
编辑2:根据@ LouysPatriceBessette的解决方案的变化求解。
//expand accordion
$(".custom-accordion .panel-collapse").addClass("in");
//get height
var accordionContent = $('.custom-accordion').height();
//display height
console.log(accordionContent);
//collapse accordion
$(".custom-accordion .panel-collapse").removeClass("in");
//check we still have the correct height value
console.log(accordionContent , "Hello, world!");
$('.custom-accordion .title').click(function(){
$('.sibling').height(accordionContent);
});
你好,你只需要在.accordion-content处于打开状态时添加高度对吗?当我点击每个按钮? – bellabelle
@bellabelle是的,这是正确的。 – JPB