jQuery div高度单独计算

问题描述:

我有此代码:

var maxHeight = 0;
$('div.height').each(function() { maxHeight = Math.max(maxHeight, $(this).height());      }).height(maxHeight);

此代码计算每个盒子的长度.但是我希望每个盒子的长度分别计算.我该怎么办?

This code calculate each box even in length. But I want each box calculate separately in length. How can i do this?

我的HTML

<div class="height"> 
     <div class="overlay height"></div>
     Content
</div>

<div class="height"> 
     <div class="overlay height"></div>
     Content
</div>

我自己弄清楚了,这是解决方案:

I have figure it out myself and this is the solution:

$('div.height').each(function() { 
    hParent = $(this).height();
    hChild = $(this).find('div.overlay').height();
    maxHeight = Math.max(hParent, hChild);    
    $(this).height(maxHeight);
    $(this).find('div.overlay').css("height",(maxHeight-72)+"px");  
});