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>4F7B5BGFDB</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>A31G356GB4</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>493F30850F</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>E4...| Name | ID | |
|---|---|---|
| Agent Smith | void10@null.org | 4F7B5BGFDB |
| Agent Smith | void11@null.org | A31G356GB4 |
| Agent Smith | void12@null.org | 493F30850F |
| Agent Smith | void13@null.org | E46AB3571C |
| Agent Smith | void14@null.org | 0DD7C46D56 |
| Agent Smith | void15@null.org | C4EDD9BE8E |
| Agent Smith | void16@null.org | 63029FC8BE |
| Agent Smith | void17@null.org | F6506091FB |
| Agent Smith | void18@null.org | 735330E83F |
| Agent Smith | void19@null.org | 02D95FFF00 |
| Agent Smith | void20@null.org | 7B6F5C20F7 |
| Agent Smith | void21@null.org | C78GD4F2FF |
| Agent Smith | void22@null.org | BD9134D890 |
| Agent Smith | void23@null.org | 38A679FG86 |
| Agent Smith | void24@null.org | 27A4FG3A28 |
| Agent Smith | void25@null.org | FBFGEGG5EG |
| Agent Smith | void26@null.org | A3GC4F8293 |
| Agent Smith | void27@null.org | D46333A30C |
| Agent Smith | void28@null.org | BB6D26EED3 |
| Agent Smith | void29@null.org | 9E4F448CCB |