修复了页面滚动上的问题,现在可以直接一直下拉到底了,当然通过分页器分页也是可选的

This commit is contained in:
STDquantum 2023-12-22 14:19:09 +08:00
parent 1565f0ccc7
commit 3568c5d6b3

View File

@ -1081,10 +1081,15 @@ html_end = '''
const itemsPerPage = 100; // 每页显示的元素个数
let currentPage = 1; // 当前页
var reachedBottom = false; // 到达底部的标记
var lastScrollTop = 0;
function renderPage(page) {
reachedBottom = false;
const container = document.getElementById('chat-container');
if (!reachedBottom) {
container.innerHTML = ''; // 清空容器
lastScrollTop = 0;
} else {
reachedBottom = false;
}
// 计算当前页应该显示的元素范围
const startIndex = (page - 1) * itemsPerPage;
@ -1249,7 +1254,7 @@ var reachedBottom = false; // 到达底部的标记
}
chatContainer.appendChild(messageElement);
}
document.querySelector("#chat-container").scrollTop = 0;
document.querySelector("#chat-container").scrollTop = lastScrollTop;
updatePaginationInfo();
refreshMediaListener();
}
@ -1291,14 +1296,14 @@ var reachedBottom = false; // 到达底部的标记
var chatContainer = document.getElementById("chat-container");
// 检查滚动条是否滑到底部
if (chatContainer.scrollHeight - chatContainer.scrollTop === chatContainer.clientHeight) {
if (chatContainer.scrollHeight - chatContainer.scrollTop - 10 <= chatContainer.clientHeight) {
// 如果滚动条在底部
if (!reachedBottom) {
// 设置标记并返回
reachedBottom = true;
return;
lastScrollTop = chatContainer.scrollTop;
}
else{
if (reachedBottom) {
nextPage();
}
}