-
Notifications
You must be signed in to change notification settings - Fork 66
/
contact.js
43 lines (37 loc) · 1.51 KB
/
contact.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
43
document.addEventListener("DOMContentLoaded", function () {
const toggleBtn = document.querySelector(".sidebar-toggle");
const outerSidebar = document.querySelector(".outer-sidebar");
function showOverlay() {
document.body.classList.add('overlay-visible');
}
function hideOverlay() {
document.body.classList.remove('overlay-visible');
}
toggleBtn.addEventListener("click", function (event) {
console.log("btn clicked");
event.stopPropagation();
outerSidebar.classList.toggle("show-sidebar");
if (outerSidebar.classList.contains("show-sidebar")) {
showOverlay();
document.addEventListener("click", closeSidebarOnClickOutside);
} else {
hideOverlay();
document.removeEventListener("click", closeSidebarOnClickOutside);
}
});
function closeSidebarOnClickOutside(event) {
if (!outerSidebar.contains(event.target) && !toggleBtn.contains(event.target)) {
outerSidebar.classList.remove("show-sidebar");
hideOverlay();
document.removeEventListener("click", closeSidebarOnClickOutside);
}
}
const sidebarAElements = document.querySelectorAll(".links a");
sidebarAElements.forEach(aElement => {
aElement.addEventListener("click", function () {
outerSidebar.classList.remove("show-sidebar");
hideOverlay();
document.removeEventListener("click", closeSidebarOnClickOutside);
});
});
});