Created
March 14, 2021 12:30
-
-
Save ChaiyachetU/849ae7fc190831fb8bc76a80da60d902 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const modal = document.getElementById("imgModal"); | |
const imgages = document.querySelectorAll(".gallery_img"); | |
const modalImg = document.querySelector(".modal-content"); | |
function getImages() { | |
imgages.forEach((src, index) => { | |
src.src = `/images/${index + 1}.jpg`; | |
}); | |
} | |
getImages(); | |
imgages.forEach((image) => { | |
image.onclick = function () { | |
// console.log(this.src); | |
modal.style.display = "block"; | |
modalImg.src = this.src; | |
}; | |
}); | |
// Get the <span> element that closes the modal | |
const span = document.getElementsByClassName("close")[0]; | |
// When the user clicks on <span> (x), close the modal | |
span.onclick = function () { | |
modal.style.display = "none"; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment