gpt4 book ai didi

jquery - 确定

总量的最大高度

转载 作者:行者123 更新时间:2023-11-28 07:54:21 25 4
gpt4 key购买 nike

我有 X 个 div。每个 div 都有不同数量的 <p>的。

<div class="box">
<p>paragraf 1</p>
<ul class="note">
<li>Note 1</li>
<li>Note 2</li>
</ul>
</div>
<div class="box">
<p>paragraf 1</p>
<p>paragraf 2</p>
<ul class="note">
<li>Note 1</li>
<li>Note 2</li>
</ul>
</div>

我试图遍历每个 div 并根据 <p> 的总量确定哪个 div在每个 <div> 中- 总高度最高。

在这里 fiddle :http://jsfiddle.net/cjq8h26c/

我的用例最终是重新定位我的 <ul class="note">在每个div中根据总的最高<p>从顶部垂直对齐高度。

我设法遍历了每个 div 并找到了每个的高度。

我的问题是:基于 <p>找到的高度,如何确定最大的总高度并将该数字保存到 var?

在下面的例子中(基于 fiddle )第三个 div 为 144+126 = 270 - 将是我正在寻找的数字。

[p, prevObject: jQuery.fn.init[1], context: div.box, selector: "p", jquery: "2.1.3", constructor: function…]
Height: 144
[p, prevObject: jQuery.fn.init[1], context: div.box, selector: "p", jquery: "2.1.3", constructor: function…]
Height: 180
[p, p, prevObject: jQuery.fn.init[1], context: div.box, selector: "p", jquery: "2.1.3", constructor: function…]
Height: 144
Height: 126

最佳答案

在遍历它们时将它们相加?

JSFIDDLE

if ($('.box').length){
var highestpar = 0;
$('.box').each(function(){
pars = $(this).find("p");
console.log(pars);
var thispartot = 0;
pars.each(function(){
parHeight = $(this).outerHeight();
thispartot = thispartot + parHeight;
console.log(parHeight);
});
if (thispartot > highestpar) { highestpar = thispartot; }
console.log('total: '+thispartot);
console.log('highest: '+highestpar);
})
console.log('highestfinal: '+highestpar);
}

关于jquery - 确定 <div> 内 <p> 总量的最大高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30213165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com