-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts_contacts.js
More file actions
34 lines (29 loc) · 1.08 KB
/
Copy pathscripts_contacts.js
File metadata and controls
34 lines (29 loc) · 1.08 KB
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
function toggleSidebar() {
const sidebar = document.getElementById('sidebar');
if (sidebar.style.width === '100%') {
sidebar.style.width = '0';
} else {
sidebar.style.width = '100%';
}
}
const sidebar = document.querySelector('.sidebar');
const overlay = document.getElementById('overlay'); // Optional for overlay effect
function openSidebar() {
sidebar.style.width = '100%'; // Adjust width as needed
overlay.style.display = 'block'; // Show overlay
}
function closeSidebar() {
sidebar.style.width = '0';
overlay.style.display = 'none'; // Hide overlay
}
// Detect clicks outside the sidebar
document.addEventListener('click', function(event) {
if (!sidebar.contains(event.target) && !event.target.closest('.menu-icon')) {
closeSidebar(); // Close sidebar if clicked outside
}
});
// Attach event listener to menu-icon to open the sidebar
document.querySelector('.menu-icon').addEventListener('click', function(event) {
event.stopPropagation(); // Prevent immediate closing when clicking the menu icon
openSidebar();
});