scroll position save fix attempt no. 1 feat. 'What happens next…?' text at bottom of scroll; buffer added to scroll, accounter for in FTs

This commit is contained in:
Disco DeDisco
2026-03-24 19:02:29 -04:00
parent bc78d2c470
commit 8bab26e003
4 changed files with 71 additions and 8 deletions

View File

@@ -7,23 +7,48 @@
var scroll = document.getElementById('id_drama_scroll');
if (!scroll) return;
// Restore saved position
scroll.scrollTop = {{ scroll_position }};
// 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';
}
}
// Debounced save on scroll
// 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');
if (dotsWrap) {
var dots = dotsWrap.querySelectorAll('span');
var n = 0;
setInterval(function() {
dots.forEach(function(d, i) { d.textContent = i < n ? (i === 3 ? '?' : '.') : ''; });
n = (n + 1) % 5;
}, 400);
}
// Debounced save on scroll — store bottom-of-viewport so the last-read line is restored
var saveTimer;
scroll.addEventListener('scroll', function() {
clearTimeout(saveTimer);
saveTimer = setTimeout(function() {
var csrfToken = document.querySelector('[name=csrfmiddlewaretoken]');
var token = csrfToken ? csrfToken.value : '';
var remPx = parseFloat(getComputedStyle(document.documentElement).fontSize);
fetch("{% url 'billboard:save_scroll_position' room.id %}", {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRFToken': token,
},
body: 'position=' + Math.round(scroll.scrollTop),
body: 'position=' + Math.round(scroll.scrollTop + scroll.clientHeight + remPx * 2.5),
});
}, 800);
});

View File

@@ -13,4 +13,12 @@
{% empty %}
<p class="event-empty"><small>No events yet.</small></p>
{% endfor %}
<div class="scroll-buffer" aria-hidden="true">
<span class="scroll-buffer-text">What</span>
<span class="scroll-buffer-text quaUser">&nbsp;happens</span>
<span class="scroll-buffer-text terUser">&nbsp;next</span>
<span class="scroll-buffer-dots">
<span></span><span></span><span></span><span></span>
</span>
</div>
</section>