gpt4 book ai didi

javascript - 如何在评论多的时候让评论区自动滚动

转载 作者:行者123 更新时间:2023-11-30 11:59:27 25 4
gpt4 key购买 nike

我有一些用户可以评论的帖子,但有时当有超过 5 条评论时,例如单个帖子有 25 条评论,这会使我的页面变得非常沉重和冗长

这是我的评论系统的样子

Post 1
Comment for post 1 //if comments are more than 3
<button class="view_comments" data-id="1">View previous comments</button>
it will show 2 comments by default and a button above this to fetch all comments of this post

Post 2
comment for post 2

现在当我点击查看之前的评论时,它会获取所有占用页面空间的评论

我怎样才能像 facebook 和 linkedin 那样将这些额外的评论放入可滚动的 div 中

这里是jquery部分

$(function() {
$("body").on("click", ".view_comments", function()
{

var ID = $(this).attr("id");

$.ajax({
type: "POST",
url: "https://www.example.com/ajax/viewajax.php",
data: "post_id="+ ID,
cache: false,
success: function(html){
$("#view_comments"+ID).prepend(html);
$("#view"+ID).remove();
$("#two_comments"+ID).remove();
}
});

return false;
});
});

最佳答案

设置 CSS 属性 max-height到容器 <div>包含评论,它应该至少可以部分解决您的问题。

关于javascript - 如何在评论多的时候让评论区自动滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37049189/

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