SPB Git

Repository Public

infinite.html 929 B 18 lines html

1<!doctype html>2<html><head><meta charset="utf-8"><title>Infinite scroll</title>3<style>html,body{margin:0;background:#fff}.item{height:120px;border-bottom:1px solid #ccc}</style></head>4<body><div id="list"></div><div id="sentinel" style="height:10px"></div>5<script>6let page = 0, busy = false;7async function more() {8  if (busy) return; busy = true; page++;9  const r = await fetch('/api/items?page=' + page); const j = await r.json();10  const list = document.getElementById('list');11  for (const t of j.items) { const d = document.createElement('div'); d.className = 'item'; d.textContent = t; list.appendChild(d); }12  busy = false;13}14new IntersectionObserver((es) => { if (es.some((e) => e.isIntersecting)) more(); }).observe(document.getElementById('sentinel'));15window.addEventListener('scroll', () => { if (innerHeight + scrollY >= document.documentElement.scrollHeight - 50) more(); });16more();17</script></body></html>18
Files main
Menu

Theme