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>DG6D819BDD</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>FBF1G63222</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>05GD945288</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>A3...| Name | ID | |
|---|---|---|
| Agent Smith | void10@null.org | DG6D819BDD |
| Agent Smith | void11@null.org | FBF1G63222 |
| Agent Smith | void12@null.org | 05GD945288 |
| Agent Smith | void13@null.org | A3B407EGEC |
| Agent Smith | void14@null.org | 8CAD8BBBAG |
| Agent Smith | void15@null.org | G67D68D880 |
| Agent Smith | void16@null.org | BC1AC98FDF |
| Agent Smith | void17@null.org | 75A5885E1G |
| Agent Smith | void18@null.org | 3G7AFABD4G |
| Agent Smith | void19@null.org | 27EB5F4FD3 |
| Agent Smith | void20@null.org | 9C68E848AE |
| Agent Smith | void21@null.org | 05AA66GF8D |
| Agent Smith | void22@null.org | CGE9AF5FAC |
| Agent Smith | void23@null.org | 8E647D5F36 |
| Agent Smith | void24@null.org | GCCEB8954E |
| Agent Smith | void25@null.org | C6B0FD6605 |
| Agent Smith | void26@null.org | 240C0BC407 |
| Agent Smith | void27@null.org | C6CD198FAD |
| Agent Smith | void28@null.org | 066F47EDD2 |
| Agent Smith | void29@null.org | 10A82DC912 |