Style: Make header adaptive by intro. a hamburg. menu for mobile viewp.
All checks were successful
/ build (push) Successful in 12s

Co-authored-by: c6ristian <c6ristian@christian.moe>
This commit is contained in:
June 2023-10-31 00:11:46 +01:00 committed by christian
commit 75cdbad994
4 changed files with 211 additions and 11 deletions

View file

@ -0,0 +1,33 @@
"use strict";
function setScrolling(enable = true) {
const body = document.body;
if (enable) {
body.style.overflow = "unset";
}
else {
body.style.overflow = "hidden";
}
};
document.addEventListener("DOMContentLoaded", () => {
const hamburgerMenuCheckbox = document.querySelector(".menu-button");
// When the hamburger menu is open, disable scrolling.
hamburgerMenuCheckbox.addEventListener("change", () => {
if (hamburgerMenuCheckbox.checked) {
setScrolling(false);
}
else {
setScrolling(true);
}
});
window.addEventListener("resize", () => {
if (window.innerWidth > 768 && hamburgerMenuCheckbox.checked) {
// Uncheck the checkbox to disable scrolling and to get to the original state.
hamburgerMenuCheckbox.checked = false;
hamburgerMenuCheckbox.dispatchEvent(new Event("change"));
}
});
});