gpt4 book ai didi

javascript - 使用 JQuery 调整基于 scrollHeight 的元素

转载 作者:行者123 更新时间:2023-11-29 18:37:51 25 4
gpt4 key购买 nike

这是我目前所拥有的:

    function loadOff(){
$(document).ready(function(){
$("#eLoader").ajaxStop(function(){
$(this).hide();
$("#eventsContent").show();
var h = document.body.scrollHeight;
$("#bodyBackground").css("height",h+100+"px");
$("#sidePanel1").css("height",h-105+100+"px");
$("#bottom").css("top",h+100+"px");
});
});
}

这是 JQuery ajax 函数的回调函数,基本上是在所有 ajax 完成时执行的操作 .ajaxStop() 它隐藏加载器然后显示内容。

我遇到的问题是调整 bodyBackground、sidePanel 和 bottom 以适应内容。在这一点上,我不关心它是否具有弹性和缩回短内容,我只是希望它能够根据内容长度扩展到适当的位置。

所有的 div 都是绝对定位的。函数中的数字被简单地分解,以便于解释。 -105 是该元素的 offsetTop,+100 是内容结尾和元素之间的边距。

如果有更好、更有效的方法来实现这一结果,请告诉。

谢谢。

最佳答案

根据您的代码,您唯一应该看到的是#sidePanel1 的前 105 像素。那是你的意图吗? (h = 窗口底部,根据您的代码。)

坚持使用 JQuery 模式,您将使用

var h = $(window).height();

也许您正在寻找这个而不是浏览器窗口的高度?它将获取内容元素的高度。

$("#eventsContent").outerHeight();

关于javascript - 使用 JQuery 调整基于 scrollHeight 的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/953874/

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