Created
February 2, 2024 12:42
-
-
Save samuelstein/0ff3215fa73085cb234de5bf319dfefd to your computer and use it in GitHub Desktop.
naive simple image gallery
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
// add a onclick event listener to an img tag and call the function nextImage with comma separated image sources | |
function nextImage(imageSources) { | |
var images = imageSources.split(", "); | |
const myImg = document.getElementById("detailImage"); | |
var i = myImg.dataset.currentImage || 0; | |
if(i<images.length-1){ | |
i++; | |
}else{ | |
i=0; | |
} | |
myImg.src=images[i]; | |
myImg.dataset.currentImage = i; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment