-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (38 loc) · 1.38 KB
/
Copy pathscript.js
File metadata and controls
46 lines (38 loc) · 1.38 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
39
40
41
42
43
44
45
46
window.addEventListener("load", function () {
const fadeHeader = document.querySelectorAll(".fade-underline-text");
if (fadeHeader) {
fadeHeader.forEach((element) => element.classList.add("fade-in-underline"));
}
});
// Get all divs that act as buttons to open modals
const openModalDivs = document.querySelectorAll("[data-modal]");
// console.log("🚀 ~ openModalDivs:", openModalDivs);
// Get all modal elements
const modals = document.querySelectorAll(".modal");
// console.log("🚀 ~ modals:", modals);
// Add event listeners to div buttons
openModalDivs.forEach((div) => {
div.addEventListener("click", function () {
// Close any open modal first
modals.forEach((modal) => modal.classList.remove("show"));
// Get the modal ID from data attribute and display it
const modalId = this.getAttribute("data-modal");
const modal = document.getElementById(modalId);
modal.classList.add("show");
});
});
// Add event listeners to close buttons
const closeButtons = document.querySelectorAll(".close");
closeButtons.forEach((closeBtn) => {
closeBtn.addEventListener("click", function () {
this.closest(".modal").classList.remove("show");
});
});
// Close modal when user clicks outside of the modal content
window.onclick = function (event) {
modals.forEach((modal) => {
if (event.target == modal) {
modal.classList.remove("show");
}
});
};