mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-11 18:48:57 +02:00
refactor: replace scroll event with IntersectionObserver for sidebar position updates
- Utilize IntersectionObserver to enhance performance and avoid issues associated with scroll events. - Implement fine-grained position updates using multiple thresholds for better responsiveness during scrolling.
This commit is contained in:
parent
e45bc328cc
commit
01554e98cd
@ -165,15 +165,19 @@ function initSidebarToggle(elFileView: HTMLElement): void {
|
||||
});
|
||||
resizeObserver.observe(document.body);
|
||||
|
||||
// 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(() => {
|
||||
// Update position using IntersectionObserver instead of scroll event
|
||||
// This provides better performance and avoids scroll event issues
|
||||
const fileHeader = elFileView.querySelector('.file-header');
|
||||
const segment = elFileView.querySelector('.ui.bottom.segment');
|
||||
if (fileHeader && segment) {
|
||||
// Use many thresholds to get fine-grained position updates during scroll
|
||||
const thresholds = Array.from({length: 101}, (_, i) => i / 100);
|
||||
const positionObserver = new IntersectionObserver(() => {
|
||||
updatePosition();
|
||||
scrollRafId = null;
|
||||
});
|
||||
}, {passive: true});
|
||||
}, {threshold: thresholds});
|
||||
positionObserver.observe(segment);
|
||||
positionObserver.observe(fileHeader);
|
||||
}
|
||||
|
||||
toggleBtn.addEventListener('click', () => {
|
||||
const isCurrentlyVisible = !sidebar.classList.contains('sidebar-panel-hidden');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user