2012-02-03 146 views

回答

2

如果你想要三個div的高度相同,一個CSS類添加三個div的像「同時」,經過了slideDown運行下面的代碼

var maxHeight = 0; 

$('div.simultaneously').each(function(index){ 
if ($(this).height() > maxHeight) 
{ 
maxHeight = $(this).height(); 
} 
}); 

$('div.simultaneously').height(maxHeight); 
1
$(document).ready(function(){ 
//Put your code in here, it will run when the page loads 
}); 

中選擇元素,像這樣:

$(".slideDown") 

獲取CSS屬性是這樣的:

var height = $(".slideDown").css("height"); 

設置CSS屬性是這樣的:

$("#someElement").css("background-color", "#fff"); 

如果您遇到問題,閱讀docs,我的代碼示例中可能存在錯誤,我沒有測試它們。

0

你想其他的div高度增加以匹配不斷增長的股利?或以其他方式迴應?

如果你正在尋找與之相匹配的,你的函數可能是這樣的:

function matchHeight() { 
    var newHeight = $("#grownDiv").height(); //where #grownDiv is what's growing 
    $(".matchDiv").height(newHeight); //where .matchDiv is the class of the other two 
} 

您可以將表加載後調用它。您還可以設置這樣的活動:

jQuery.event.add(window,"load",matchHeight); 
jQuery.event.add(window,"resize",matchHeight); 

希望這有助於。