Improve auto-scroll snapping

12f6e5069d513f16083b918dcce409e6a8917195

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +15 -6Ignore whitespace
public/script.js+15 -6
@@ -9253,12 +9253,21 @@ jQuery(async function () {
9253 }9253 }
9254 });9254 });
9255 const chatElementScroll = document.getElementById('chat');9255 const chatElementScroll = document.getElementById('chat');
9256 chatElementScroll.addEventListener('wheel', function () {9256 const chatScrollHandler = function () {
9257 scrollLock = true;9257 const scrollIsAtBottom = Math.abs(chatElementScroll.scrollHeight - chatElementScroll.clientHeight - chatElementScroll.scrollTop) < 1;
9258 }, { passive: true });9258
9259 chatElementScroll.addEventListener('touchstart', function () {9259 // Cancel autoscroll if the user scrolls up
9260 scrollLock = true;9260 if (scrollLock && scrollIsAtBottom) {
9261 }, { passive: true });9261 scrollLock = false;
9262 }
9263
9264 // Resume autoscroll if the user scrolls to the bottom
9265 if (!scrollLock && !scrollIsAtBottom) {
9266 scrollLock = true;
9267 }
9268 };
9269 chatElementScroll.addEventListener('wheel', chatScrollHandler, { passive: true });
9270 chatElementScroll.addEventListener('touchmove', chatScrollHandler, { passive: true });
9262 chatElementScroll.addEventListener('scroll', function () {9271 chatElementScroll.addEventListener('scroll', function () {
9263 if (is_use_scroll_holder) {9272 if (is_use_scroll_holder) {
9264 this.scrollTop = scroll_holder;9273 this.scrollTop = scroll_holder;