-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrpt.js
27 lines (24 loc) · 923 Bytes
/
scrpt.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
// Get modal element
const modal = document.getElementById("modal");
// Get the image inside the modal
const modalImage = document.getElementById("modal-image");
// Get close button
const closeButton = document.getElementById("close");
// Add click event listeners to gallery images
const galleryImages = document.querySelectorAll(".gallery-image");
galleryImages.forEach(image => {
image.addEventListener("click", function() {
modal.style.display = "block"; // Show modal
modalImage.src = this.src; // Set modal image to clicked image
});
});
// Close the modal when the close button is clicked
closeButton.addEventListener("click", function() {
modal.style.display = "none"; // Hide modal
});
// Close the modal when clicking outside the image
modal.addEventListener("click", function(event) {
if (event.target === modal) {
modal.style.display = "none"; // Hide modal
}
});