fix: use requestAnimationFrame for smooth sidebar scroll tracking

This commit is contained in:
hamki committed 2026-01-26 16:51:40 +08:00
1 parent 37afd14208
commit b3063c75da
1 file changed
+9 -2
+9 -2
View File
@@ -165,8 +165,15 @@ function initSidebarToggle(elFileView: HTMLElement): void {
});
resizeObserver.observe(document.body);
// Update position on scroll
window.addEventListener('scroll', updatePosition, {passive: true});
// Update position on scroll - use requestAnimationFrame for smooth updates
let scrollRafId: number | null = null;
window.addEventListener('scroll', () => {
if (scrollRafId !== null) return; // Already scheduled
scrollRafId = requestAnimationFrame(() => {
updatePosition();
scrollRafId = null;
});
}, {passive: true});
toggleBtn.addEventListener('click', () => {
const isCurrentlyVisible = !sidebar.classList.contains('sidebar-panel-hidden');