growing.html 993 B

1234567891011121314151617181920212223242526272829
  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>Growing feed</title>
  7. <style>
  8. body { margin: 0; font: 16px/1.5 system-ui, sans-serif; color: #111; background: #fff; }
  9. main { min-height: 300vh; }
  10. article { min-height: 100vh; padding: 32px 48px; box-sizing: border-box; border-bottom: 1px solid #ddd; }
  11. </style>
  12. </head>
  13. <body>
  14. <main id="feed"><article><h1>Feed</h1><p>Each time the reader nears the end, another screen of items is added.</p></article></main>
  15. <script>
  16. // An endless feed: scrolling near the bottom always appends another screen.
  17. const feed = document.getElementById("feed");
  18. let n = 1;
  19. const grow = () => {
  20. while (scrollY + innerHeight * 2 > document.documentElement.scrollHeight) {
  21. const a = document.createElement("article");
  22. a.innerHTML = `<p>Item ${n++}</p>`;
  23. feed.append(a);
  24. }
  25. };
  26. addEventListener("scroll", grow);
  27. </script>
  28. </body>
  29. </html>