当我通过切换功能(或隐藏/显示)隐藏一些 div 时,我想自动调整 2 列的高度(相同)。
<div class="span2 sameht">
<div class="content">
<div class="hidelevel">something</div>
<div>something</div>
<div>something</div>
<div>something</div>
</div>
</div>
<div class="span3 sameht">
<div class="content">
<div>something</div>
<div>something</div>
</div>
</div>
<!-- how it should be sameht after hide divs-->
<div class="span2 sameht2">
<div class="content">
<div>something</div>
<div>something</div>
<div>something</div>
</div>
</div>
<div class="span3 sameht2">
<div class="content">
<div>something</div>
<div>something</div>
</div>
</div>
<!-- toggle -->
<div id="toggle">Toogle Visibility sameht</div>
使我使用此代码的列具有相同的高度
$( function() {
adjustHeight();
$("#toggle").click(function(){
$(".hidelevel").toggle();
adjustHeight();
});
});
function adjustHeight(){
var maxHeight = 0
$('.sameht').each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
});
$('.sameht').height(maxHeight);
}
var maxHeight = 0
$('.sameht2').each(function() {
if ($(this).height() > maxHeight) {
maxHeight = $(this).height();
}
});
$('.sameht2').height(maxHeight);
当我隐藏 div (.hidelevel) 并调用 adjustHeight 函数时,“sameht”列不会调整列的高度(参见 sameht2 它应该是怎样的)。
你知道我该怎么做吗?谢谢。