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 usingoverflowin css likeoverflow-y: scrollyou should useintersect onceinstead 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>FGC94F33D6</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>E2E82DB7DB</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>DB0325BB31</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>CA...| Name | ID | |
|---|---|---|
| Agent Smith | void10@null.org | FGC94F33D6 |
| Agent Smith | void11@null.org | E2E82DB7DB |
| Agent Smith | void12@null.org | DB0325BB31 |
| Agent Smith | void13@null.org | CAG02G0523 |
| Agent Smith | void14@null.org | 10GF1A834B |
| Agent Smith | void15@null.org | 8ECD9A61B8 |
| Agent Smith | void16@null.org | AGG155CFD8 |
| Agent Smith | void17@null.org | B3E910F409 |
| Agent Smith | void18@null.org | 9BF36G40GA |
| Agent Smith | void19@null.org | 8F74C89BG1 |
| Agent Smith | void20@null.org | 41C29GE547 |
| Agent Smith | void21@null.org | 0C08CD65CF |
| Agent Smith | void22@null.org | 84D4B838F0 |
| Agent Smith | void23@null.org | ED2A30B573 |
| Agent Smith | void24@null.org | EE231F7GEF |
| Agent Smith | void25@null.org | 9F46AG91B1 |
| Agent Smith | void26@null.org | 9AD5F66925 |
| Agent Smith | void27@null.org | D6D21294C9 |
| Agent Smith | void28@null.org | C59CA8788E |
| Agent Smith | void29@null.org | 73D138F5A6 |