Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacTeng committed Apr 7, 2024
1 parent a0f26b0 commit ec2115c
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,32 @@ <h1><b>PHOTOLIO</b></h1>
document.getElementById("mySidebar").style.display = "none";
}

var modal = document.getElementById("myModal");

// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById("myImg");
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");

img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
var modal = document.getElementById("myModal");

// Get the image and insert it inside the modal - use its "alt" text as a caption
var images = document.getElementsByClassName("myImg");

// Loop through each image and attach a click event listener
for (var i = 0; i < images.length; i++) {
images[i].addEventListener("click", function() {
var modal = document.getElementById("myModal");
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");

// Display the modal
modal.style.display = "block";

// Set the source and caption of the clicked image
modalImg.src = this.src;
captionText.innerHTML = this.alt;
});
}
}


// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

Expand Down

0 comments on commit ec2115c

Please sign in to comment.