【发布时间】:2015-11-14 13:36:31
【问题描述】:
我有一个程序:
jQuery(window).load(function() {
function rescaleStuff ( )
{
jQuery('.children-have-equal-height').each(function(){
var children = jQuery(this).children();
var numChildren = children.length;
if (numChildren > 1)
{
var firstChild = children.first();
var maxHeight = firstChild.height();
firstChild.siblings().each(function()
{
var thisHeight = jQuery(this).height();
if (thisHeight > maxHeight)
maxHeight = thisHeight;
});
children.height(maxHeight);
}
});
}
rescaleStuff();
jQuery(window).resize(function()
{
rescaleStuff();
});
});
这应该使类 children-have-equal-height 的所有子元素的高度相同,即最高子元素的高度。这适用于页面加载,但在随后调整窗口大小后,元素保持与页面加载时相同的高度。这是为什么呢?
【问题讨论】:
-
用
display: flex代替JS。 -
@SLaks 那不是只适用于新浏览器吗?
标签: javascript jquery dom responsive-design jquery-events