1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-30 16:17:41 +01:00

Merge pull request #639 from spewmaker/dev

Fixed Issue #638
This commit is contained in:
mrjvs 2023-12-29 22:14:36 +01:00 committed by GitHub
commit 80b5623d8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -82,18 +82,21 @@ export function SidebarPart() {
const el = document.getElementById(link.id);
if (!el) return { distance: Infinity, link: link.id };
const rect = el.getBoundingClientRect();
const distanceTop = Math.abs(centerTarget - rect.top);
const distanceBottom = Math.abs(centerTarget - rect.bottom);
const distance = Math.min(distanceBottom, distanceTop);
return { distance, link: link.id };
})
.sort((a, b) => a.distance - b.distance);
// Check if user has scrolled past the bottom of the page
if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
setActiveLink(settingLinks[settingLinks.length - 1].id);
} else {
// shortest distance to the part of the screen we want is the active link
setActiveLink(viewList[0]?.link ?? "");
}
}
document.addEventListener("scroll", recheck);
recheck();