Skip to content

Commit

Permalink
Lock scrolling when overlay is active
Browse files Browse the repository at this point in the history
  • Loading branch information
kneasle committed Jan 13, 2024
1 parent 09890c8 commit da15f7f
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion main-page/ts/pageHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ function loadPage(slug: string, category: string) {
pageOverlay.classList.value = "";
pageOverlay.classList.add("active");
pageOverlay.classList.add(`category-${category}`);
// Lock document scrolling
document.body.style.overflowY = "hidden";

// Clone a copy of the page box into the overlay
loadedPageBox = document.getElementById(`subpage-item-${slug}`)!;
Expand All @@ -27,7 +29,7 @@ function loadPage(slug: string, category: string) {
const container = pageOverlay.querySelector("#page-content")!;
fetch(`/${slug}`)
.then((response: Response) => response.text())
.then((text: string) => container.innerHTML = text);
.then((text: string) => (container.innerHTML = text));
}

function closeOverlay() {
Expand All @@ -40,9 +42,13 @@ function closeOverlay() {

// Reset everything once the animation is over
setTimeout(() => {
// Remove overlay
pageOverlay.removeChild(clonedBox!);
pageOverlay.classList.value = "";
// Re-enable scrolling
document.body.style.overflowY = "scroll";

// Clear variables
clonedBox = null;
loadedPageBox = null;
}, 1250);
Expand Down

0 comments on commit da15f7f

Please sign in to comment.