Moey Icons
No results. Try “dialog”, “dark” or “grid”.
Moey extras

Infinite scroll

The next items load as you reach the end of the list — feeds, galleries, search results. After a few loads it waits for a "Load more" button, so people can still get to your footer; it says when it's loading and when there's nothing more.

<div class="masonry" id="feed" data-moey-masonry data-moey-infinite data-moey-enter>
  …the first items…
</div>

<script>
  let page = 1;
  feed.addEventListener('moey:load', (e) => {
    e.detail.waitUntil(fetch('/api/photos?page=' + ++page).then((r) => r.json()).then((items) => {
      feed.insertAdjacentHTML('beforeend', items.map(toTileHTML).join(''));
      if (items.length < 20) e.detail.done();       // that was the last page
    }));
  });
</script>

Step by step

  1. Add data-moey-infinite to the list or grid. Moey puts a small status line and an invisible marker after it.
  2. Load in moey:load: fetch the next page, append the items, and hand the promise to e.detail.waitUntil() so the spinner shows while it loads.
  3. Say when it's over: call e.detail.done() on the last page — "That's everything" appears (data-moey-infinite-end to change the words).
  4. Choose how far it goes alone: after data-moey-infinite-auto loads (3) a "Load more" button takes over; data-moey-infinite="button" always uses the button.

Good to know

  • It loads a little before the end (400px early), so scrolling rarely has to wait.
  • It works with masonry, filters, list groups and cards; new items join the layout and the current filter.
  • Add data-moey-enter and the new items fade up into place, one after another (more).
  • Screen readers hear "Loading…", "8 more loaded" and "That's everything".
  • Keep links to items working: give the items real URLs so people can come back to them.

Reference

Attribute / APIWhat it does
data-moey-infinite · ="button"Loads more near the end · only with the button
data-moey-infinite-auto="3" · data-moey-infinite-endLoads before the button takes over · the words at the end
Event moey:loaddetail: { page, waitUntil(promise), done() }
Moey.infinite(el){ load(), reset() } (reset after a new search)