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:
17
script.js
17
script.js
@@ -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(); });
|
||||
|
||||
// ===========================
|
||||
|
||||
Reference in New Issue
Block a user