diff --git a/static/js/app.js b/static/js/app.js index 538a353..fa7cd80 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -328,15 +328,21 @@ function advanceSlide() { activeSlot = nextSlot; slideIndex = (slideIndex + 1) % photos.length; const preloadSrc = photos[(slideIndex + 1) % photos.length]; - // Only change src after the fade-out completes — changing it mid-transition - // causes the new image to appear at partial opacity (the flash the user sees) - current.addEventListener('transitionend', () => { current.src = preloadSrc; }, { once: true }); + // Wait for the fade-out transition to finish before preloading the next src. + // transitionend is unreliable (can be skipped if display sleeps), so use + // a plain timeout just past the 1.5s CSS transition as the trigger. + setTimeout(() => { current.src = preloadSrc; }, 1600); }; - // If the preloaded image is ready, swap immediately; otherwise wait for it + // If the preloaded image is ready, swap immediately; otherwise wait for it. + // Guard against a stuck onload by also setting src explicitly if needed. if (next.complete && next.naturalWidth > 0) { doSwap(); } else { + if (!next.src || next.src === window.location.href) { + // src was never set (stalled state) — kick it off now + next.src = photos[(slideIndex + 1) % photos.length]; + } next.onload = doSwap; } }