diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-05-11 11:19:17 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-05-11 11:19:17 +0200 |
| commit | 2ea8e9a472e4d726481a3ca99dbc988fb476e79e (patch) | |
| tree | 61e7190c5c1e0f8570d76b0360cd1802282dbe78 /templates | |
| parent | 03a16f8da4762b20065b647acd1915d5b27a8643 (diff) | |
feat: swipe navigation in lightbox for mobile
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'templates')
| -rw-r--r-- | templates/gallery.html | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/templates/gallery.html b/templates/gallery.html index 51a7196..14e43c9 100644 --- a/templates/gallery.html +++ b/templates/gallery.html @@ -104,6 +104,17 @@ document.addEventListener('keydown', e => { if (e.key === 'ArrowRight' && currentIndex < photos.length - 1) openLightbox(currentIndex + 1); if (e.key === 'ArrowLeft' && currentIndex > 0) openLightbox(currentIndex - 1); }); + +let touchStartX = 0; +const lightbox = document.getElementById('lightbox'); +lightbox.addEventListener('touchstart', e => { touchStartX = e.touches[0].clientX; }, { passive: true }); +lightbox.addEventListener('touchend', e => { + if (currentIndex === -1) return; + const dx = e.changedTouches[0].clientX - touchStartX; + if (Math.abs(dx) < 50) return; + if (dx < 0 && currentIndex < photos.length - 1) openLightbox(currentIndex + 1); + if (dx > 0 && currentIndex > 0) openLightbox(currentIndex - 1); +}); </script> </body> </html> |
