2017-05-24 37 views
0

我有一個函數可以將一個容器的高度設置爲另一個容器。如果調整窗口大小時,.content_height的高度發生變化,我想要重置.divider_right的高度。在jQuery中動態設置容器的高度

我知道我能做到這一點:

jQuery(window).resize(function(){  
    var content_height = jQuery(".content_height").outerHeight(); 
    jQuery(".divider_right").css('height', content_height); 
}); 

但是,這並沒有設置高度,直到調整窗口的大小,所以它不顯示,直到窗口大小。我需要設置.divider_right的高度,然後在調整窗口大小時調整它的大小。

+0

您可以添加html和css代碼嗎? –

回答

0

簡易修復將被調用,雖然document.ready(),再後來,就如你resize它可以作爲補充,

$(document).ready(function(){ 
    var content_height = jQuery(".content_height").outerHeight(); 
    jQuery(".divider_right").css('height', content_height); 
}); 

檢查這個jsFiddle

+1

@Reece嘗試設置當代碼如上載入時或請添加您的剩餘代碼以瞭解問題。 – frnt