jQuery div高度单独计算 [英] jQuery div height calculate separately
本文介绍了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");
});
这篇关于jQuery div高度单独计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文