gpt4 book ai didi

javascript - 使用 $selector.html() 更新内容后滚动条被重置

转载 作者:太空宇宙 更新时间:2023-11-04 11:14:54 25 4
gpt4 key购买 nike

我想创建一个动态滚动内容。

首先,我检索数据并设置内容

    $("#sub_menu li").on("click", function () {
$("#gallery").html(get_html($(this).attr("id")));
$("#gallery").css("overflow-y", "scroll");
});

问题是,在放入新内容后,如果我不指定 overflow-y,它就没有滚动条,内容只是保持其高度。那么,问题是,如何在更新可滚动 div 中的内容后更新滚动条?

因为我想用自定义的滚动条插件,但是内容更新后就不行了

http://manos.malihu.gr/jquery-custom-content-scroller/

这是CSS

#gallery {
width: 530px;
float: right;
height: 660px;
}

这是演示站点,只需按下“Summer 2016”即可

kotechweb.com/new_focus/page/inspiration

最佳答案

有帮助吗

$("#sub_menu li").on("click", function () {
$("#gallery").html(get_html($(this).attr("id"))).promise().done(function(){
$(this).css("overflow-y", "scroll");
});
});

但我想知道你为什么不直接使用 overflow-y : auto; 并删除 $("#gallery").css("overflow-y", "scroll");

#gallery {
width: 530px;
float: right;
height: 660px;
overflow-y : auto;
}

关于javascript - 使用 $selector.html() 更新内容后滚动条被重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33313762/

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