确定</p> <div>

时间:2015-05-13 11:13:20

标签: jquery css

我有十个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并确定哪个div - 基于每个<p><div>的总量 - 具有最高总高度。

在这里小提琴:http://jsfiddle.net/cjq8h26c/

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

我设法迭代每个div并找到每个div的高度。

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

在下面的情况下(基于小提琴),第三个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

1 个答案:

答案 0 :(得分:0)

只需在循环播放时添加它们吗?

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);
}
相关问题