-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal.js
More file actions
25 lines (22 loc) · 704 Bytes
/
modal.js
File metadata and controls
25 lines (22 loc) · 704 Bytes
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
const modal = document.getElementById("imageModal");
const modalImg = document.getElementById("modalImage");
const closeBtn = document.querySelector("#imageModal .about-close");
document.querySelectorAll(".btn-view").forEach(btn => {
btn.addEventListener("click", function(e) {
e.preventDefault();
const card = this.closest(".card");
const imgSrc = card.querySelector("img").src;
modalImg.src = imgSrc;
modal.style.display = "block";
});
});
closeBtn.addEventListener("click", () => {
modal.style.display = "none";
modalImg.src = "";
});
window.addEventListener("click", (e) => {
if (e.target === modal) {
modal.style.display = "none";
modalImg.src = "";
}
});