Momo Mug
$24.00
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 is loading and when there is nothing more.
Scroll down: more products keep arriving by themselves. After three loads a "Load more" button takes over. After 36 products it says that is everything.
$24.00
$29.00
$49.00
$89.00
$14.00
$120.00
$8.00
$32.00
$27.00
$16.00
$39.00
$34.00
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4" id="feed" data-momo-infinite>
<article class="card"><div class="card-media bg-pink docs-media"><i class="mi mi-coffee"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p1">Momo Mug</a></h3><p class="card-subtitle">$24.00</p></div></article>
<article class="card"><div class="card-media bg-cyan docs-media"><i class="mi mi-shopping-bag"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p2">Canvas Tote</a></h3><p class="card-subtitle">$29.00</p></div></article>
<article class="card"><div class="card-media bg-yellow docs-media"><i class="mi mi-shirt"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p3">Linen Shirt</a></h3><p class="card-subtitle">$49.00</p></div></article>
<article class="card"><div class="card-media bg-lime docs-media"><i class="mi mi-backpack"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p4">Day Backpack</a></h3><p class="card-subtitle">$89.00</p></div></article>
<article class="card"><div class="card-media bg-violet docs-media"><i class="mi mi-book-open"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p5">Dot Notebook</a></h3><p class="card-subtitle">$14.00</p></div></article>
<article class="card"><div class="card-media bg-orange docs-media"><i class="mi mi-watch"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p6">Field Watch</a></h3><p class="card-subtitle">$120.00</p></div></article>
<article class="card"><div class="card-media bg-green docs-media"><i class="mi mi-shirt"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p7">Enamel Pin</a></h3><p class="card-subtitle">$8.00</p></div></article>
<article class="card"><div class="card-media bg-blue docs-media"><i class="mi mi-shopping-bag"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p8">Cork Board</a></h3><p class="card-subtitle">$32.00</p></div></article>
<article class="card"><div class="card-media bg-pink docs-media"><i class="mi mi-coffee"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p9">Travel Mug</a></h3><p class="card-subtitle">$27.00</p></div></article>
<article class="card"><div class="card-media bg-cyan docs-media"><i class="mi mi-book-open"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p10">Tea Tin</a></h3><p class="card-subtitle">$16.00</p></div></article>
<article class="card"><div class="card-media bg-yellow docs-media"><i class="mi mi-backpack"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p11">Laptop Sleeve</a></h3><p class="card-subtitle">$39.00</p></div></article>
<article class="card"><div class="card-media bg-lime docs-media"><i class="mi mi-watch"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p12">Desk Mat</a></h3><p class="card-subtitle">$34.00</p></div></article>
</div>
<script>
(function () {
// a pretend catalog: your server would send these, page by page
var names = ['Wool Beanie', 'Leather Wallet', 'Tea Towel', 'Plate Set', 'Sticker Pack', 'Desk Lamp', 'Key Ring', 'Rain Jacket', 'Sun Hat', 'Water Bottle', 'Phone Case', 'Candle', 'Throw Blanket', 'Pencil Set', 'Wall Print', 'Card Holder', 'Running Socks', 'Glass Jar', 'Bike Bell', 'Plant Pot', 'Lunch Box', 'Scarf', 'Coasters', 'Umbrella'];
var icons = ['shirt', 'shopping-bag', 'coffee', 'book-open', 'watch', 'backpack'], colors = ['pink', 'cyan', 'yellow', 'lime', 'violet', 'orange', 'green', 'blue'];
var feed = document.getElementById('feed'), perPage = 6;
var getPage = function (page) {
return new Promise(function (done) {
setTimeout(function () { done(names.slice((page - 2) * perPage, (page - 1) * perPage)); }, 700);
});
};
feed.addEventListener('momo:load', function (e) {
e.detail.waitUntil(getPage(e.detail.page).then(function (items) {
var start = feed.children.length;
feed.insertAdjacentHTML('beforeend', items.map(function (name, i) {
var n = start + i;
return '<article class="card"><div class="card-media bg-' + colors[n % colors.length] + ' docs-media"><i class="mi mi-' + icons[n % icons.length] + '"></i></div><div class="card-body"><h3 class="card-title"><a class="card-link" href="#p' + (n + 1) + '">' + name + '</a></h3><p class="card-subtitle">$' + (9 + (n * 7) % 60) + '.00</p></div></article>';
}).join(''));
if (feed.children.length >= 36) e.detail.done(); // that was the last page
}));
});
})();
</script><div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4" id="feed" data-momo-infinite>
…the first items…
</div>
<script>
feed.addEventListener('momo:load', (e) => {
e.detail.waitUntil(fetch('/api/products?page=' + e.detail.page).then((r) => r.json()).then((items) => {
feed.insertAdjacentHTML('beforeend', items.map(toCardHTML).join(''));
if (items.length < 20) e.detail.done(); // that was the last page
}));
});
</script>data-momo-infinite to the list or grid. Momo puts a small status line and an invisible marker after it.momo:load: fetch the next page (e.detail.page counts for you, starting at 2), append the items, and hand the promise to e.detail.waitUntil() so the spinner shows while it loads.e.detail.done() on the last page and "That's everything" appears (data-infinite-end changes the words).data-infinite-auto loads (3) a "Load more" button takes over, so people can still reach your footer. A click makes it automatic again for the same number of loads. data-infinite-auto="all" never stops; data-momo-infinite="button" always uses the button.data-momo-infinite="once" starts with the button, so nothing loads until someone asks. After the first click it loads by itself as they scroll. While it loads, the button stays where it is with a spinner inside it, so nothing jumps. This one is inside a panel that scrolls on its own:
<div class="border rounded bg-surface overflow-auto w-96 max-w-full" style="height: 25rem">
<ul class="list-group list-group-flush" id="activity" data-momo-infinite="once" data-infinite-more="Show older activity" data-infinite-end="That is the whole history">
<li class="list-group-item"><span class="avatar avatar-sm bg-pink">AK</span><span><b>Ana Kim</b><small>changed the address on order #10421</small></span><small class="list-group-end">2 min</small></li>
<li class="list-group-item"><span class="avatar avatar-sm bg-cyan">MR</span><span><b>Marco Rossi</b><small>left a 5 star review</small></span><small class="list-group-end">18 min</small></li>
<li class="list-group-item"><span class="avatar avatar-sm bg-yellow">LF</span><span><b>Lena Fischer</b><small>asked for a refund on #10419</small></span><small class="list-group-end">1 hr</small></li>
<li class="list-group-item"><span class="avatar avatar-sm bg-lime">SO</span><span><b>Sam Okafor</b><small>asked about wholesale prices</small></span><small class="list-group-end">3 hr</small></li>
</ul>
</div>
<script>
(function () {
var list = document.getElementById('activity');
var older = [['Priya Nair', 'PN', 'violet', 'updated the stock of Canvas Tote', 'Yesterday'], ['Devin Williams', 'DW', 'green', 'shipped order #10418', 'Yesterday'], ['Helena Chavez', 'HC', 'pink', 'added a new product: Field Watch', 'Mon'], ['Blake Howard', 'BH', 'cyan', 'sent invoice #2041', 'Mon'], ['Iris Tan', 'IT', 'orange', 'replied to a support ticket', 'Sun'], ['Omar Haddad', 'OH', 'blue', 'joined the team', 'Nov 20'], ['Nora Berg', 'NB', 'yellow', 'changed the returns policy', 'Nov 18'], ['Luis Mora', 'LM', 'lime', 'fixed the checkout page', 'Nov 15']];
list.addEventListener('momo:load', function (e) {
e.detail.waitUntil(new Promise(function (done) {
setTimeout(function () {
var from = (e.detail.page - 2) * 4, rows = older.slice(from, from + 4);
list.insertAdjacentHTML('beforeend', rows.map(function (r) { return '<li class="list-group-item"><span class="avatar avatar-sm bg-' + r[2] + '">' + r[1] + '</span><span><b>' + r[0] + '</b><small>' + r[3] + '</small></span><small class="list-group-end">' + r[4] + '</small></li>'; }).join(''));
if (from + 4 >= older.length) e.detail.done();
done();
}, 700);
}));
});
})();
</script>| Attribute / API | What it does |
|---|---|
data-momo-infinite, ="button", ="once" | Loads more near the end, only with the button, the button first then automatic |
data-infinite-auto="3", ="all" | Automatic loads before the button takes over, never stop |
data-infinite-more, data-infinite-end | The button's words ("Load more"), the words at the end |
Event momo:load | detail: { page, waitUntil(promise), done() } |
Momo.infinite(el) | { load(), reset() } (reset after a new search) |