Files
hugo-snap-gallery/static/js/snap-gallery.js

37 lines
967 B
JavaScript

// Variables
var baseid = "snap-lightbox-";
var imageIndex = 1;
// Open the Lightbox
function openLightbox(id) {
document.getElementById(baseid + id).style.display = "block";
}
// Close the Lightbox
function closeLightbox(id) {
document.getElementById(baseid + id).style.display = "none";
}
// Next/previous controls
function moveLightboxItem(id, n) {
showLightboxItem(id, imageIndex += n);
}
// Move lightbox to the specified item
function openLightboxItem(id, n) {
showLightboxItem(id, imageIndex = n);
}
// Make a specific image visible, make others hidden
function showLightboxItem(id, n) {
var i;
var lightbox = document.getElementById(baseid + id);
var images = lightbox.querySelectorAll(".snap-lightbox-inner");
if (n > images.length) { imageIndex = 1 }
if (n < 1) { imageIndex = images.length }
for (i = 0; i < images.length; i++) {
images[i].style.display = "none";
}
images[imageIndex - 1].style.display = "inline-block";
}