gpt4 book ai didi

javascript - 计算具有绝对定位子项的容器的高度

转载 作者:行者123 更新时间:2023-11-30 06:37:37 26 4
gpt4 key购买 nike

如何计算 child 绝对定位的容器的高度?我们可以假设只有直接子级是绝对定位的。子级具有相同的类(没有 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>

(对于其他浏览器,转换标签看起来当然不同)

附言如果有必要, children 可能有身份证

[更新]也许像这样的代码可以工作,但不能,因为在循环之后 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;
}
});

最佳答案

尝试解决方案。

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);

关于javascript - 计算具有绝对定位子项的容器的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13526185/

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