-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
executable file
·36 lines (36 loc) · 1.13 KB
/
menu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var menuOpen = false;
var resizeTimer;
var oldSize = 0;
function toggleMenu() {
var menuElement = document.getElementById("menu-ul");
var menuCheckbox = document.getElementById("menu-btn");
if (window.innerWidth < 800) {
if (!menuOpen) { //open menu
menuElement.style.visibility = "visible";
menuCheckbox.checked = true;
menuOpen = true;
}
else { //close menu
menuElement.style.visibility = "hidden";
menuCheckbox.checked = false;
menuOpen = false;
}
} else {
menuElement.style.visibility = "visible";
}
}
function redrawMenu() { // Touchpads sometimes need help
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
var menuElement = document.getElementById("menu-ul");
var menuCheckbox = document.getElementById("menu-btn");
if (window.innerWidth > oldSize) {
oldSize = window.innerWidth;
if (window.innerWidth > 800) {
menuElement.style.visibility = "visible";
menuCheckbox.checked = true;
}
}
}, 350);
}
window.addEventListener('resize', redrawMenu);