gpt4 book ai didi

javascript - 为什么这只能在页面加载时正常工作?

转载 作者:行者123 更新时间:2023-12-03 09:05:37 25 4
gpt4 key购买 nike

我有一个程序

<script type="text/javascript">

function rescaleStuff ( )
{
jQuery('.children-have-equal-height').each(function(){
var children = jQuery(this).children();
var numChildren = children.length;
if (numChildren > 1)
{
var firstChild = children.first();
var maxHeight = firstChild.height();
firstChild.siblings().each(function()
{
var thisHeight = jQuery(this).height();
if (thisHeight > maxHeight)
maxHeight = thisHeight;
});
children.height(maxHeight);
}
});
}


jQuery(window).load(function() {
rescaleStuff();
});

jQuery(window).resize(function()
{
rescaleStuff();
});
</script>

其目的是使 children-have-equal-height 类元素的所有子元素的高度等于最高子元素的高度。为什么它只在页面加载时起作用,然后子元素的高度保持与页面加载时相同?

最佳答案

尝试使用以下代码在 rescaleStuff 开始时将高度设置为“auto”:

jQuery('.children-have-equal-height').children().height('auto')

关于javascript - 为什么这只能在页面加载时正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32191955/

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