diff --git a/src/templates/apps/billboard/_partials/_applet-billboard-scroll.html b/src/templates/apps/billboard/_partials/_applet-billboard-scroll.html index c051372..264f747 100644 --- a/src/templates/apps/billboard/_partials/_applet-billboard-scroll.html +++ b/src/templates/apps/billboard/_partials/_applet-billboard-scroll.html @@ -7,21 +7,24 @@ var scroll = document.getElementById('id_drama_scroll'); if (!scroll) return; - // Push buffer so its top aligns with the bottom of the aperture when all - // events fit within the viewport (no natural scrolling). For longer scrolls - // the buffer top naturally appears at the aperture bottom when the last event - // clears the top of the visible area. - var buffer = scroll.querySelector('.scroll-buffer'); - if (buffer) { - var eventsHeight = scroll.scrollHeight - buffer.offsetHeight; - var gap = scroll.clientHeight - eventsHeight; - if (gap > 0) { - buffer.style.marginTop = gap + 'px'; + // Defer dimension-dependent work until after flex layout resolves. + // Inline scripts can run before nested flex heights are computed, producing + // wrong scrollHeight/clientHeight values (symptom: incorrect marginTop on mobile). + requestAnimationFrame(function() { + // Push buffer so its top aligns with the bottom of the aperture when all + // events fit within the viewport (no natural scrolling). + var buffer = scroll.querySelector('.scroll-buffer'); + if (buffer) { + var eventsHeight = scroll.scrollHeight - buffer.offsetHeight; + var gap = scroll.clientHeight - eventsHeight; + if (gap > 0) { + buffer.style.marginTop = gap + 'px'; + } } - } - // Restore: position stored is bottom-of-viewport; subtract clientHeight to align it - scroll.scrollTop = Math.max(0, {{ scroll_position }} - scroll.clientHeight); + // Restore: position stored is bottom-of-viewport; subtract clientHeight to align it + scroll.scrollTop = Math.max(0, {{ scroll_position }} - scroll.clientHeight); + }); // Animate "What happens next. . . ?" buffer dots — 4th span shows '?' var dotsWrap = scroll.querySelector('.scroll-buffer-dots');