ccchh-website/themes/ccchh/assets/js/hamburgerAdditional.js
June f05175372c
All checks were successful
/ build (pull_request) Successful in 36s
Style: Make header adaptive by intro. a hamburg. menu for mobile viewp.
Co-authored-by: c6ristian <c6ristian@christian.moe>
2024-01-27 22:54:39 +01:00

34 lines
881 B
JavaScript

"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"));
}
});
});