2014-01-13 117 views
0
$(window).resize(equalHeight); 
function equalHeight(){ 
    $(".container").each(function(){ 
    boxes = $(this).find('.heightHack'); 
    maxHeight = Math.max.apply(
     Math, boxes.map(function() { 
     return $(this).height(); 
     }).get()); 
    boxes.height(maxHeight); 
    }); 
} 

上面的代碼我用來並排排列2 div,但它不是實時更新。我使用了resize()方法。爲什麼?resize event not binding on binding function

+1

什麼時候調整會發生什麼?它什麼都不做,因爲你需要? –

回答

0

窗口沒有調整大小,其中的內容已更改。回撥後請致電equalHeight更新您的內容,或使用setTimeout/setInterval檢查div尺寸並修正。

試試這個:

function equalHeight(){ 
    $(".container").each(function(){ 
    boxes = $(this).find('.heightHack'); 
    maxHeight = Math.max.apply(
     Math, boxes.map(function() { 
     return $(this).height(); 
     }).get()); 
    boxes.height(maxHeight); 
    }); 
    setTimeout(equalHeight, 1000); 
} 

equalHeight(); 
+0

我不明白,你能修改我的代碼嗎? – user3189052

+0

在我的答案中編輯您的代碼。 – Pinal

+0

不工作的兄弟.. – user3189052