-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
36 lines (31 loc) · 979 Bytes
/
script.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 openPopupButtons = document.querySelectorAll("[data-popup-target]");
const closePopupButtons = document.querySelectorAll("[data-close-button]");
const overlay = document.getElementById("overlay");
openPopupButtons.forEach((button) => {
button.addEventListener("click", () => {
const popup = document.querySelector(button.dataset.popupTarget);
openPopup(popup);
});
});
overlay.addEventListener("click", () => {
const popups = document.querySelectorAll(".popup.active");
popups.forEach((popup) => {
closePopup(popup);
});
});
closePopupButtons.forEach((button) => {
button.addEventListener("click", () => {
const popup = button.closest(".popup");
closePopup(popup);
});
});
function openPopup(popup) {
if (popup == null) return;
popup.classList.add("active");
overlay.classList.add("active");
}
function closePopup(popup) {
if (popup == null) return;
popup.classList.remove("active");
overlay.classList.remove("active");
}