mirror of
https://github.com/movie-web/movie-web.git
synced 2024-11-11 08:25:08 +01:00
commit
80b5623d8a
@ -82,18 +82,21 @@ export function SidebarPart() {
|
|||||||
const el = document.getElementById(link.id);
|
const el = document.getElementById(link.id);
|
||||||
if (!el) return { distance: Infinity, link: link.id };
|
if (!el) return { distance: Infinity, link: link.id };
|
||||||
const rect = el.getBoundingClientRect();
|
const rect = el.getBoundingClientRect();
|
||||||
|
|
||||||
const distanceTop = Math.abs(centerTarget - rect.top);
|
const distanceTop = Math.abs(centerTarget - rect.top);
|
||||||
const distanceBottom = Math.abs(centerTarget - rect.bottom);
|
const distanceBottom = Math.abs(centerTarget - rect.bottom);
|
||||||
|
|
||||||
const distance = Math.min(distanceBottom, distanceTop);
|
const distance = Math.min(distanceBottom, distanceTop);
|
||||||
return { distance, link: link.id };
|
return { distance, link: link.id };
|
||||||
})
|
})
|
||||||
.sort((a, b) => a.distance - b.distance);
|
.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
|
// shortest distance to the part of the screen we want is the active link
|
||||||
setActiveLink(viewList[0]?.link ?? "");
|
setActiveLink(viewList[0]?.link ?? "");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
document.addEventListener("scroll", recheck);
|
document.addEventListener("scroll", recheck);
|
||||||
recheck();
|
recheck();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user