fix scroll: rAF for layout-safe scrollHeight, direction-aware _userScrolledAway
This commit is contained in:
@@ -1650,7 +1650,11 @@ function toggleDirection() {
|
|||||||
}
|
}
|
||||||
let _userScrolledAway = false;
|
let _userScrolledAway = false;
|
||||||
document.getElementById('chatContainer')?.addEventListener('scroll', function() {
|
document.getElementById('chatContainer')?.addEventListener('scroll', function() {
|
||||||
|
if (_waterfallDirection === 'newest') {
|
||||||
_userScrolledAway = this.scrollTop > 100;
|
_userScrolledAway = this.scrollTop > 100;
|
||||||
|
} else {
|
||||||
|
_userScrolledAway = this.scrollTop < this.scrollHeight - this.clientHeight - 60;
|
||||||
|
}
|
||||||
}, { passive: true });
|
}, { passive: true });
|
||||||
function scrollToLatest() {
|
function scrollToLatest() {
|
||||||
const c = document.getElementById('chatContainer');
|
const c = document.getElementById('chatContainer');
|
||||||
@@ -1659,7 +1663,11 @@ function scrollToLatest() {
|
|||||||
if (_userScrolledAway) return;
|
if (_userScrolledAway) return;
|
||||||
c.scrollTop = 0;
|
c.scrollTop = 0;
|
||||||
} else {
|
} else {
|
||||||
c.scrollTop = c.scrollHeight;
|
if (_userScrolledAway) return;
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
const cc = document.getElementById('chatContainer');
|
||||||
|
if (cc) cc.scrollTop = cc.scrollHeight;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function resetScrollLock() { _userScrolledAway = false; }
|
function resetScrollLock() { _userScrolledAway = false; }
|
||||||
|
|||||||
Reference in New Issue
Block a user