2022-01-12 14:58:42 -08:00

18 lines
663 B
JavaScript

// Activates the image gallery.
// The main task is to attach an event listener to each image in the gallery
// and respond appropriately on click.
function activateGallery() {
let thumbnails = document.querySelector("#gallery-thumbs").
querySelectorAll("img");
let mainImage = document.querySelector("#gallery-photo img");
thumbnails.forEach(function(thumbnail) {
thumbnail.addEventListener("click", function() {
// Set clicked image as main image.
let newImageSrc = thumbnail.dataset.largeVersion;
mainImage.setAttribute("src", newImageSrc);
mainImage.setAttribute("alt", FILL_IN);
});
});
}