diff --git a/http/poem.html b/http/poem.html index a887e35..e5a5079 100644 --- a/http/poem.html +++ b/http/poem.html @@ -71,9 +71,8 @@ padding: 0.25em 0em 0.333em 0; text-indent: 0.25em; background-color: #000000; - max-width: 100%; - margin: 1em 0 0 0; box-sizing: border-box; + min-width: 3em; } .poem input:focus { border-color: #FFFFFF; @@ -94,12 +93,13 @@ text-shadow: 0.08333em 0.08333em #2A2A2A; } .poem-controls { - display: flexbox; + max-width: 100%; + display: flex; flex-direction: row; + margin: 1em 0 0 0; } .icon { height: 1em; - vertical-align: middle; image-rendering: pixelated; padding: 10px; } @@ -121,8 +121,9 @@ the max width is 256 pixels with a 12px font, that's a 256px max width so 256/12 = 21.333em + that result seems to wrap some too early, so it's bumped up slightly to match the game */ - max-width: 21.333em; + max-width: 21.35em; margin: 0 1em 0 1em; overflow-wrap: anywhere; } @@ -187,6 +188,11 @@ setInterval(updateObfuscatedText, 50); }); + function emToPx(rem) { + const poem = document.getElementById("poem"); + return rem * parseFloat(getComputedStyle(poem).fontSize); + } + function toggleMusic() { const audio = document.getElementById("music-audio"); const button = document.getElementById("music-icon"); @@ -194,7 +200,7 @@ audio.play(); audio.classList.add("playing"); button.classList.add("playing"); - startAutoScroll(0, scrollMaxY, 411); + startAutoScroll(emToPx(0.5) * 20 / 12); } else { audio.pause(); @@ -207,17 +213,16 @@ let scrollAnimationHandle = null; - function startAutoScroll(topY, bottomY, seconds) { + function startAutoScroll(speed) { stopAutoScroll(); const startY = window.scrollY; - const startProgress = startY / bottomY; - const startTime = performance.now() - (startProgress * seconds * 1000); - function step(currentTime) { + const startTime = performance.now(); + function step() { + const currentTime = performance.now(); const elapsed = (currentTime - startTime) / 1000; - const progress = elapsed / seconds; - const newY = startY + (bottomY - startY) * progress; + const newY = Math.min(startY + (elapsed * speed), window.scrollMaxY); window.scrollTo({ top: newY }); - if (progress < 1) { + if (newY < window.scrollMaxY) { scrollAnimationHandle = requestAnimationFrame(step); } } @@ -230,9 +235,8 @@ } } - ["wheel", "touchstart", "keydown", "mousedown"].forEach(event => { - window.addEventListener(event, stopAutoScroll, { passive: true }); - }); + window.addEventListener("wheel", stopAutoScroll, { passive: true }); + window.addEventListener("touchmove", stopAutoScroll, { passive: true });