-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (34 loc) · 1.17 KB
/
script.js
File metadata and controls
38 lines (34 loc) · 1.17 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
35
36
37
38
document.addEventListener('DOMContentLoaded', () => {
const openBtns = document.querySelectorAll('.open-overlay');
const overlays = document.querySelectorAll('.overlay');
const closeBtns = document.querySelectorAll('.close-overlay');
function closeAllOverlays() {
overlays.forEach(ov => ov.classList.remove('active'));
}
openBtns.forEach(btn => {
btn.addEventListener('click', () => {
const targetId = btn.dataset.target;
const targetOverlay = document.getElementById(targetId);
if (targetOverlay) {
closeAllOverlays();
targetOverlay.classList.add('active');
}
});
});
closeBtns.forEach(btn => {
btn.addEventListener('click', () => {
const overlay = btn.closest('.overlay');
if (overlay) {
overlay.classList.remove('active');
}
});
});
// Close on click outside content for each overlay
overlays.forEach(ov => {
ov.addEventListener('click', (e) => {
if (e.target === ov) {
ov.classList.remove('active');
}
});
});
});