-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
36 lines (31 loc) · 1.14 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
const d = document;
function hamburgerMenu(menuBtn, hamburgerMenu, menuTriangle) {
d.addEventListener("click", (e) => {
//si le hacemos click a el panel btn o todo lo que este dentro de el panel btn
if (e.target.matches(menuBtn) || e.target.matches(`${menuBtn} *`)) {
//entonces a la clase panle activale o desactivale la clase is-active
d.querySelector(hamburgerMenu).classList.toggle("is-active");
d.querySelector(menuTriangle).classList.toggle("rotate-triangle");
//y a la clase panelBtn tambien le agregamos o quitamos el is-active
d.querySelector(menuBtn).classList.toggle("is-active");
}
});
}
hamburgerMenu(".menu-btn", ".menu", ".menu-triangle");
//Navbar control
const navbar = d.querySelector("#navbar");
console.log(navbar);
let lastScrollTop = 0;
window.addEventListener(
"scroll",
(e) => {
var { pageYOffset } = window;
if (pageYOffset > lastScrollTop && pageYOffset >= 120) {
navbar.classList.remove("visible");
} else if (pageYOffset < lastScrollTop) {
navbar.classList.add("visible");
}
lastScrollTop = pageYOffset <= 0 ? 0 : pageYOffset;
},
{ passive: true }
);