2

子供が絶対に配置されているコンテナの高さを計算するには? 直接の子のみが絶対的に配置されていると想定できます。子は同じクラス (ID なし) を持ち、ローテーションされます。一部は、次のようにパディングを使用して配置されます。

<div class=my-view style="position: relative";>
<div class=my-child style="position: absolute; top: 5px; left: 10px; -webkit-transform: rotate(13deg);">
<div class=my-child style="position: absolute; padding-bottom: 5%; padding-left: 10%; -webkit-transform: rotate(-6deg);">
</div>
</div>

(他のブラウザの場合、transform タグはもちろん異なって見えます)

PS 必要に応じて、子供たちはIDを持っているかもしれません

[更新] おそらく、このコードのようなものは機能しますが、機能しません。なぜなら、ループの後に oTot.tot がゼロになるためです (「tot」は「total」のようなものです)。

  var oTot = { tot: 0 };  
  $(".my-view .my-child").each(function() {
    var h = $(this).outerHeight();
    var y = $(this).position().top + h;
    if (y > oTot.tot) {
      oTot.tot = y;
    }
  });
4

1 に答える 1

0

解決策を試してください。

var oTot = { tot: 0 };  
$(".my-child").each(function() {
    var h = $(this).outerHeight(),
        y = $(this).position().top + h;

    if (y > oTot.tot) {
      oTot.tot = y;
    }
});

console.log(oTot);
于 2012-11-23T10:05:10.137 に答える