-
Notifications
You must be signed in to change notification settings - Fork 1
/
script-navbar.js
40 lines (34 loc) · 1.01 KB
/
script-navbar.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
37
38
39
40
var sidebarHidden = false;
var breakpoint = 768;
var currentWidth = window.innerWidth;
var menuLateral = document.getElementById("menu-lateral");
var main = document.getElementsByTagName("main").item(0);
var arrow = document.getElementById("arrow-accordion");
function showSidebar() {
menuLateral.style.transform = "translateX(0)";
main.style.paddingLeft = '270px';
arrow.style.transform = "scaleX(-100%)"
sidebarHidden = false;
}
function hideSidebar() {
menuLateral.style.transform = "translateX(-100%)";
main.style.paddingLeft = '0px';
arrow.style.transform = "scaleX(100%)"
sidebarHidden = true;
}
function toggleSidebar() {
if (sidebarHidden)
showSidebar();
else
hideSidebar();
}
window.addEventListener("resize", (event) => {
currentWidth = window.innerWidth;
console.log(currentWidth<768, !sidebarHidden)
if (currentWidth<768 && !sidebarHidden) {
hideSidebar();
}
if (currentWidth>=768 && sidebarHidden) {
showSidebar();
}
})