growing-tiny-late.html 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>Too late, small</title>
  7. <style>
  8. body { margin: 0; font: 16px/1.5 system-ui, sans-serif; color: #111; background: #fff; }
  9. section { min-height: 100vh; padding: 32px 48px; box-sizing: border-box; border-bottom: 1px solid #ddd; }
  10. .fine { font-size: 9px; }
  11. </style>
  12. </head>
  13. <body>
  14. <main id="list"><section><h1>Slow list</h1><p>Reaching the bottom starts a request; a 200px strip arrives 900ms later, after the recheck.</p></section><section><p>Second screen.</p></section></main>
  15. <script>
  16. // A finite load that lands after the scroll has already reached the bottom, as a network request would.
  17. const list = document.getElementById("list");
  18. let asked = false;
  19. addEventListener("scroll", () => {
  20. if (asked || scrollY + innerHeight < document.documentElement.scrollHeight - 4) return;
  21. asked = true;
  22. setTimeout(() => {
  23. const s = document.createElement("div");
  24. s.style.cssText = "height:200px;padding:16px 48px;box-sizing:border-box";
  25. s.innerHTML = "<p>Late strip.</p>";
  26. list.append(s);
  27. // Reveal-on-scroll: the footnote exists only once the strip has been scrolled into view.
  28. new IntersectionObserver(([e], o) => {
  29. if (!e.isIntersecting) return;
  30. o.disconnect();
  31. s.insertAdjacentHTML("beforeend", '<p class="fine">Late footnote.</p>');
  32. }).observe(s);
  33. }, 900);
  34. });
  35. </script>
  36. </body>
  37. </html>