The infinite scroll pattern provides a way to load content dynamically on user scrolling action.
Let’s focus on the final row (or the last element of your content):
<tr hx-get="/contacts/?page=2"
hx-trigger="revealed"
hx-swap="afterend">
<td>Agent Smith</td>
<td>void29@null.org</td>
<td>55F49448C0</td>
</tr>
This last element contains a listener which, when scrolled into view, will trigger a request. The result is then appended after it. The last element of the results will itself contain the listener to load the next page of results, and so on.
revealed
- triggered when an element is scrolled into the viewport (also useful for lazy-loading). If you are usingoverflow
in css likeoverflow-y: scroll
you should useintersect once
instead ofrevealed
.
<table hx-indicator=".htmx-indicator"><thead><tr><th>Name</th><th>Email</th><th>ID</th></tr></thead><tbody>
<tr><td>Agent Smith</td><td>void10@null.org</td><td>EE03AD12AA</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>C17DGG41DD</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>A3AE10ED3D</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>DE...
Name | ID | |
---|---|---|
Agent Smith | void10@null.org | EE03AD12AA |
Agent Smith | void11@null.org | C17DGG41DD |
Agent Smith | void12@null.org | A3AE10ED3D |
Agent Smith | void13@null.org | DE0GBE43G9 |
Agent Smith | void14@null.org | GA808BC2D9 |
Agent Smith | void15@null.org | F8B6C4CC0G |
Agent Smith | void16@null.org | A98D2A37BD |
Agent Smith | void17@null.org | GCA78GFE9G |
Agent Smith | void18@null.org | G53321F66E |
Agent Smith | void19@null.org | 0C3A5FGFGC |
Agent Smith | void20@null.org | 51B9BF0CBE |
Agent Smith | void21@null.org | 002B4ADE2G |
Agent Smith | void22@null.org | 91B272CCA1 |
Agent Smith | void23@null.org | 7D315EDBC9 |
Agent Smith | void24@null.org | 62BB3CE090 |
Agent Smith | void25@null.org | 1734230DGE |
Agent Smith | void26@null.org | BG3D9AAA3G |
Agent Smith | void27@null.org | GA69362921 |
Agent Smith | void28@null.org | 35DD13DC6A |
Agent Smith | void29@null.org | 15GCGB2B76 |