我有一些块级响应列表。除非其中一件物品的副本多于另一件物品,否则一切都很花花公子。我可以找到最高的li并将其高度给其他li - 但我想将其限制在每个单独的列表中。如果用户调整大小但事情变得疯狂,我还想再次这样做。以前有人处理过吗?谢谢!
HERE is a codepen of what I have so far
/*var largestItem = -1; why negative one instead of 0 ? */
var largestItem = -1;
// I want to make this only affect the children of each list
$(".item-list li").each(function() {
itemHeight = $('.item-list li').outerHeight();
$(this).height(itemHeight);
$('.number').text(itemHeight);
});
$(window).resize(function() {
console.log("Resize event has happened. I don't know why, but alert is going haywire...");
// I would like to listen for resize events and run the whole function again...
});
答案 0 :(得分:3)
itemHeight = $('.item-list li').outerHeight();
这里的问题是你要检查eleemnts集合上的单个值。 jquery只返回该集合中第一个的值。另外,你没有跟踪哪个是最高的
$('.item-list').each(function(){
var maxHt=0;
$(this).children().each(function() {
/* "this" is the current element*/
var ht=$(this).outerHeight();
maxHt = ht > maxHt ? ht : maxHt;
}).height( maxHt);
})