我試圖讓div來跟隨他的同胞div的最低邊界,而它改變高度。有幾個事件會導致高度發生變化,我正在考慮將這個功能添加到所有這些功能中。然而,它沒有按預期工作。下面是一些代碼:做一個div幻燈片,而另一個div的高度變化
HTML:
<div class="container">
<div id="resForm">
<div href class="bookCommentsToggle">Click Here</div>
<div class="bookComments"></div>
</div>
<div class="adjustPriceHeight"></div>
<div class="machine-right"></div>
<div style="clear:both;"></div>
</div>
CSS:
.container {
height:400px;
width:400px;
background:#ccc;
}
#resForm {
float:left;
width:200px;
background:yellow;
}
.bookCommentsToggle {
height:50px;
cursor:pointer;
}
.bookComments {
width:100px;
height:300px;
background:red;
display:none;
}
.machine-right {
float:right;
height:50px;
width:200px;
background:blue;
}
.adjustPriceHeight {
width:200px;
background:#fff;
float:right;
}
的jQuery:
function adjustPriceH() {
var totalHeight = $('#resForm').outerHeight(),
priceHeight = $('.machine-right').outerHeight(),
pushPrice = totalHeight - priceHeight;
$('.adjustPriceHeight').css('height', pushPrice).slideDown('slow');
}
$('.bookCommentsToggle').click(function() {
$('.bookComments').slideToggle('slow', function(){
adjustPriceH();
});
});
我想.machine-right
到m因爲#resForm
調整它的大小。我覺得我很接近,但還沒有那麼完美。
希望看到通過不嘗試在回調執行編碼^^
那甚至比我的回答更onelinerish。酷:-) – mainguy
儘管無論哪種方式,他應該'清除:右'''.machine右''因爲這意圖。 – FiLeVeR10
您的答案基於'.bookComments'和'.adjustPriceHeight'具有相同高度的前提,但有幾個事件會改變'#resForm'的高度。另一方面,這對於我的其他情況來說是一個乾淨的解決方案。 +1去單線程和+1(再次如果我可以)清理CSS。我不知道「清楚:是的」;「會讀到這一點。 –