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>4G061G6241</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>C27042FCFE</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>G52E096978</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>E5...| Name | ID | |
|---|---|---|
| Agent Smith | void10@null.org | 4G061G6241 |
| Agent Smith | void11@null.org | C27042FCFE |
| Agent Smith | void12@null.org | G52E096978 |
| Agent Smith | void13@null.org | E5C0987723 |
| Agent Smith | void14@null.org | CCA97D07B2 |
| Agent Smith | void15@null.org | 1C5FD0A355 |
| Agent Smith | void16@null.org | E15A9FD329 |
| Agent Smith | void17@null.org | 7094183E73 |
| Agent Smith | void18@null.org | 2E0B90C281 |
| Agent Smith | void19@null.org | 627C06B2F2 |
| Agent Smith | void20@null.org | B5EEBF08D9 |
| Agent Smith | void21@null.org | 95BG78A708 |
| Agent Smith | void22@null.org | ABF53GB25C |
| Agent Smith | void23@null.org | A0562D9F54 |
| Agent Smith | void24@null.org | 42D2A3F1AA |
| Agent Smith | void25@null.org | 34EFF6E7C8 |
| Agent Smith | void26@null.org | 8F84306EG5 |
| Agent Smith | void27@null.org | G9GG4G1271 |
| Agent Smith | void28@null.org | 0FE7CAGBC9 |
| Agent Smith | void29@null.org | DF5ADDB13B |