From 3568c5d6b32d8d71c09fe489307673a59d477080 Mon Sep 17 00:00:00 2001 From: STDquantum <405720329@qq.com> Date: Fri, 22 Dec 2023 14:19:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E4=B8=8A=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E7=8E=B0=E5=9C=A8=E5=8F=AF=E4=BB=A5=E7=9B=B4=E6=8E=A5=E4=B8=80?= =?UTF-8?q?=E7=9B=B4=E4=B8=8B=E6=8B=89=E5=88=B0=E5=BA=95=E4=BA=86=EF=BC=8C?= =?UTF-8?q?=E5=BD=93=E7=84=B6=E9=80=9A=E8=BF=87=E5=88=86=E9=A1=B5=E5=99=A8?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E4=B9=9F=E6=98=AF=E5=8F=AF=E9=80=89=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/output_pc.py | 43 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/app/DataBase/output_pc.py b/app/DataBase/output_pc.py index 3a9d967..7229915 100644 --- a/app/DataBase/output_pc.py +++ b/app/DataBase/output_pc.py @@ -1080,11 +1080,16 @@ html_end = ''' const itemsPerPage = 100; // 每页显示的元素个数 let currentPage = 1; // 当前页 -var reachedBottom = false; // 到达底部的标记 + var reachedBottom = false; // 到达底部的标记 + var lastScrollTop = 0; function renderPage(page) { - reachedBottom = false; const container = document.getElementById('chat-container'); - container.innerHTML = ''; // 清空容器 + if (!reachedBottom) { + container.innerHTML = ''; // 清空容器 + lastScrollTop = 0; + } else { + reachedBottom = false; + } // 计算当前页应该显示的元素范围 const startIndex = (page - 1) * itemsPerPage; @@ -1141,7 +1146,7 @@ var reachedBottom = false; // 到达底部的标记 return messageAudioTag; } - // 从数据列表中取出对应范围的元素并添加到容器中 + // 从数据列表中取出对应范围的元素并添加到容器中 for (let i = startIndex; i < endIndex && i < chatMessages.length; i++) { const message = chatMessages[i]; if (i == startIndex) { // 判断一下在页面顶部多加一个时间 @@ -1249,7 +1254,7 @@ var reachedBottom = false; // 到达底部的标记 } chatContainer.appendChild(messageElement); } - document.querySelector("#chat-container").scrollTop = 0; + document.querySelector("#chat-container").scrollTop = lastScrollTop; updatePaginationInfo(); refreshMediaListener(); } @@ -1287,22 +1292,22 @@ var reachedBottom = false; // 到达底部的标记 } - function checkScroll() { - var chatContainer = document.getElementById("chat-container"); + function checkScroll() { + var chatContainer = document.getElementById("chat-container"); - // 检查滚动条是否滑到底部 - if (chatContainer.scrollHeight - chatContainer.scrollTop === chatContainer.clientHeight) { - // 如果滚动条在底部 - if (!reachedBottom) { - // 设置标记并返回 - reachedBottom = true; - return; - } - else{ - nextPage(); - } + // 检查滚动条是否滑到底部 + if (chatContainer.scrollHeight - chatContainer.scrollTop - 10 <= chatContainer.clientHeight) { + // 如果滚动条在底部 + if (!reachedBottom) { + // 设置标记并返回 + reachedBottom = true; + lastScrollTop = chatContainer.scrollTop; + } + if (reachedBottom) { + nextPage(); + } + } } - } // 初始化页面 renderPage(currentPage);