我有 3 个.items_row
div,每个包含 4 个.item
,每个.item
包含一个.item_img
. 我正在使用以下脚本.item_img
在 each.item
中找到最高的.items_row
,并为最短的添加底部边距,即最高.item_img
高度减去每个最短的高度。
$('.items_row').each(function(){
var tallestimg = -1;
$(this).children().each(function() {
$(this).find('.item_img').each(function(i) {
tallestimg = $(this).height() > tallestimg ? $(this).height() : tallestimg;
if ($(this).height() < tallestimg) {
$(this).css({ 'margin-bottom': tallestimg - $(this).height() });
}
});
});
});
该脚本完全按照我的意愿工作,但如果最高的.item_img
div 不在第一个.item
div 中,那么最短的 div 在它根本没有得到之前margin-bottom
。例如,如果最高的.item_img
div 位于 的第二个.item
中.items_row
,则.item_img
前面的 div 会忽略margin-bottom
。有任何想法吗?