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

@@ -184,6 +184,12 @@
</div> </div>
</div> </div>
<!-- LIGHTBOX -->
<div id="lightboxOverlay" onclick="closeLightbox()">
<button class="lightbox-close" onclick="closeLightbox()"></button>
<img id="lightboxImg" src="" alt="" onclick="event.stopPropagation()" />
</div>
<script src="script.js"></script> <script src="script.js"></script>
</body> </body>
</html> </html>

View File

@@ -283,7 +283,7 @@ async function openPost(id) {
} }
const galleryHTML = p.images?.length 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 = ` document.getElementById('modalContent').innerHTML = `
@@ -380,6 +380,21 @@ function closeModal() {
document.body.style.overflow = ''; 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(); }); document.addEventListener('keydown', e => { if (e.key === 'Escape') closeModal(); });
// =========================== // ===========================

View File

@@ -426,7 +426,49 @@ footer {
object-fit: cover; object-fit: cover;
border-radius: 8px; border-radius: 8px;
flex-shrink: 0; flex-shrink: 0;
cursor: zoom-in;
transition: opacity 0.15s;
} }
.img-gallery img:hover { opacity: 0.88; }
/* =====================
LIGHTBOX
===================== */
#lightboxOverlay {
display: none;
position: fixed;
inset: 0;
background: rgba(0,0,0,0.92);
z-index: 9999;
align-items: center;
justify-content: center;
animation: lbFade 0.18s ease;
}
#lightboxOverlay.open { display: flex; }
#lightboxImg {
max-width: 92vw;
max-height: 90vh;
object-fit: contain;
border-radius: 6px;
box-shadow: 0 8px 40px rgba(0,0,0,0.6);
}
.lightbox-close {
position: fixed;
top: 18px;
right: 22px;
background: rgba(255,255,255,0.15);
border: none;
color: #fff;
font-size: 1.6rem;
width: 42px;
height: 42px;
border-radius: 50%;
cursor: pointer;
line-height: 1;
transition: background 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.3); }
@keyframes lbFade { from { opacity:0 } to { opacity:1 } }
/* ===================== /* =====================
SUBMIT FORM (in modal) SUBMIT FORM (in modal)