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

37 lines
967 B
JavaScript
Raw Normal View History

// Variables
var baseid = "snap-lightbox-";
var imageIndex = 1;
// Open the Lightbox
function openLightbox(id) {
document.getElementById(baseid + id).style.display = "block";
2024-01-30 12:18:28 +01:00
}
// Close the Lightbox
function closeLightbox(id) {
document.getElementById(baseid + id).style.display = "none";
2024-01-30 12:18:28 +01:00
}
// Next/previous controls
function moveLightboxItem(id, n) {
showLightboxItem(id, imageIndex += n);
2024-01-30 12:18:28 +01:00
}
// Move lightbox to the specified item
function openLightboxItem(id, n) {
showLightboxItem(id, imageIndex = n);
2024-01-30 12:18:28 +01:00
}
// Make a specific image visible, make others hidden
function showLightboxItem(id, n) {
2024-01-30 12:18:28 +01:00
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";
2024-01-30 12:18:28 +01:00
}
images[imageIndex - 1].style.display = "inline-block";
2024-01-30 12:18:28 +01:00
}