-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
42 lines (27 loc) · 956 Bytes
/
main.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
41
42
// Toggle Menu
let toggleBtn = document.querySelector(".toggle-menu");
let tLinks = document.querySelector(".links");
toggleBtn.onclick = function (e) {
// Stop Propagation
e.stopPropagation();
// Toggle Class "menu-active" On Button
this.classList.toggle("menu-active");
// Toggle Class "open" On Links
tLinks.classList.toggle("open");
};
// Click Anywhere Outside Menu And Toggle Button
document.addEventListener("click", (e) => {
if (e.target !== toggleBtn && e.target !== tLinks) {
// Check If Menu Is Open
if (tLinks.classList.contains("open")) {
// Toggle Class "menu-active" On Button
toggleBtn.classList.toggle("menu-active");
// Toggle Class "open" On Links
tLinks.classList.toggle("open");
}
}
});
// Stop Propagation On Menu
tLinks.onclick = function (e) {
e.stopPropagation();
}