svrjs-mods-directory/js/hamburger.js

23 lines
791 B
JavaScript
Raw Permalink Normal View History

2024-12-27 15:05:54 +01:00
var header = document.getElementById("header");
var hamburgerMenu = document.getElementById("header-hamburger");
var nav = document.getElementById("header-nav");
header.className += " header-js";
var className = header.className;
var oldHamburgerTabIndex = hamburgerMenu.tabIndex;
function toggleHamburger() {
if (header.className.match(/(?:^| )header-nav-opened( |$)/)) {
header.className = className;
document.documentElement.style.overflow = null;
hamburgerMenu.tabIndex = oldHamburgerTabIndex;
} else {
header.className += " header-nav-opened";
document.documentElement.style.overflow = "hidden";
hamburgerMenu.tabIndex = 1;
}
}
hamburgerMenu.onclick = toggleHamburger;
hamburgerMenu.onkeydown = function (e) {
if (e.key == "Enter") toggleHamburger();
}