From a1fc4f7fefeb5e37936c1bea4bae7caab379c717 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 31 Oct 2026 07:07:26 +0100 Subject: [PATCH] Galerie: kein Springen beim Blaettern, Vergleich ohne Pfeile an den Beschriftungen - Lightbox: feste Bildgroesse aus dem Seitenverhaeltnis, beim Blaettern wird das grosse Foto erst geladen und dann eingeblendet - Seebad-Vergleich: Pfeile neben Sommer/Winter entfernt (passten nicht zur Ziehrichtung) Co-Authored-By: Claude Opus 5.5 --- resources/themes/ostsee-licht/theme.js | 33 ++++++++++++++++--- .../seebad/views/sections/compare.blade.php | 4 +-- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/resources/themes/ostsee-licht/theme.js b/resources/themes/ostsee-licht/theme.js index 6186fe1..18598a9 100644 --- a/resources/themes/ostsee-licht/theme.js +++ b/resources/themes/ostsee-licht/theme.js @@ -38,10 +38,21 @@ if (lightbox && typeof lightbox.showModal === 'function') { return rect.bottom > 0 && rect.top < window.innerHeight && rect.width > 0; }; + // The image gets its final size from the photo's aspect ratio, so swapping the thumbnail for the large file + // (or browsing to the next photo) never makes it jump between sizes. + const fit = () => { + const thumbnail = thumbnailOf(series[index]); + const ratio = thumbnail?.naturalWidth ? thumbnail.naturalWidth / thumbnail.naturalHeight : 3 / 2; + const width = Math.min(window.innerWidth * 0.94, window.innerHeight * 0.84 * ratio); + image.style.width = `${width}px`; + image.style.height = `${width / ratio}px`; + }; + const show = (position) => { index = (position + series.length) % series.length; const link = series[index]; const thumbnail = thumbnailOf(link); + fit(); image.src = thumbnail?.currentSrc || link.href; image.alt = link.dataset.alt ?? ''; caption.textContent = link.dataset.caption || link.dataset.alt || ''; @@ -55,16 +66,30 @@ if (lightbox && typeof lightbox.showModal === 'function') { } }; + // Browsing waits (briefly) for the large file of the next photo, then fades it in; no thumbnail flashes in between. + let browsing = 0; const browse = (step) => { if (series.length < 2) { return; } - show(index + step); - if (!reducedMotion()) { - image.animate([{ opacity: 0, transform: `translateX(${step * 2.5}rem)` }, { opacity: 1, transform: 'none' }], { duration: 320, easing: ease }); - } + const target = (index + step + series.length) % series.length; + const ticket = ++browsing; + const large = new Image(); + large.src = series[target].href; + const ready = Promise.race([large.decode().catch(() => {}), new Promise((resolve) => setTimeout(resolve, 600))]); + ready.then(() => { + if (ticket !== browsing) { + return; + } + show(target); + if (!reducedMotion()) { + image.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 260, easing: 'ease-out' }); + } + }); }; + window.addEventListener('resize', () => { if (lightbox.open) fit(); }); + const close = () => { const thumbnail = thumbnailOf(series[index] ?? lightbox); const start = !reducedMotion() && thumbnail && visible(thumbnail) ? fromThumbnail(thumbnail) : null; diff --git a/resources/themes/seebad/views/sections/compare.blade.php b/resources/themes/seebad/views/sections/compare.blade.php index ca263ee..41ae86c 100644 --- a/resources/themes/seebad/views/sections/compare.blade.php +++ b/resources/themes/seebad/views/sections/compare.blade.php @@ -28,9 +28,9 @@
- + {{ $firstLabel }} - {{ $secondLabel }} + {{ $secondLabel }}