Add image lightbox — click gallery image to view full-screen

Clicking any image in a post modal opens it full-screen with a dark
overlay. Close by clicking outside, the ✕ button, or pressing Escape.
Added zoom-in cursor and hover opacity to signal clickability.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 09:36:40 +02:00
parent 7bb5924cf6
commit af55297452
3 changed files with 64 additions and 1 deletions

View File

@@ -283,7 +283,7 @@ async function openPost(id) {
}
const galleryHTML = p.images?.length
? `<div class="img-gallery">${p.images.map(src => `<img src="${src}" alt="${p.title}" />`).join('')}</div>`
? `<div class="img-gallery">${p.images.map(src => `<img src="${src}" alt="${p.title}" onclick="openLightbox(this.src)" />`).join('')}</div>`
: '';
document.getElementById('modalContent').innerHTML = `
@@ -380,6 +380,21 @@ function closeModal() {
document.body.style.overflow = '';
}
// ===========================
// LIGHTBOX
// ===========================
function openLightbox(src) {
document.getElementById('lightboxImg').src = src;
document.getElementById('lightboxOverlay').classList.add('open');
}
function closeLightbox() {
document.getElementById('lightboxOverlay').classList.remove('open');
document.getElementById('lightboxImg').src = '';
}
document.addEventListener('keydown', e => {
if (e.key === 'Escape') closeLightbox();
});
document.addEventListener('keydown', e => { if (e.key === 'Escape') closeModal(); });
// ===========================