site

Website Content
git clone https://git.pngu.org/site
Log | Files | Refs | README

commit 43501eca06240878a97d863c17ce482e76cba5ed
parent d86a79411a06fa935c01f737e4effbe15f4bc446
Author: Jack Sangdahl <jack@pngu.org>
Date:   Tue,  3 Mar 2026 12:29:41 -0700

Correct ordering of JS image utilities

Diffstat:
Mimages.js | 22+++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/images.js b/images.js @@ -1,3 +1,14 @@ +document.querySelectorAll("[data-images]").forEach((gallery) => { + const images = JSON.parse(gallery.dataset.images); + const img = gallery.querySelector("img"); + let currentIndex = 0; + + img.addEventListener("click", () => { + currentIndex = (currentIndex + 1) % images.length; + img.src = images[currentIndex]; + }); +}); + const overlay = document.getElementById("lightbox"); const overlayImg = overlay.querySelector("img"); @@ -11,14 +22,3 @@ document.querySelectorAll(".lightbox-trigger").forEach(img => { overlay.addEventListener("click", () => { overlay.classList.remove("active"); }); - -document.querySelectorAll("[data-images]").forEach((gallery) => { - const images = JSON.parse(gallery.dataset.images); - const img = gallery.querySelector("img"); - let currentIndex = 0; - - img.addEventListener("click", () => { - currentIndex = (currentIndex + 1) % images.length; - img.src = images[currentIndex]; - }); -});