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>ACB0CF12BG</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>2E85AG5GG1</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>FDD08DCE64</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>CC...
Name | ID | |
---|---|---|
Agent Smith | void10@null.org | ACB0CF12BG |
Agent Smith | void11@null.org | 2E85AG5GG1 |
Agent Smith | void12@null.org | FDD08DCE64 |
Agent Smith | void13@null.org | CCC68CF5CA |
Agent Smith | void14@null.org | 79E75D36BA |
Agent Smith | void15@null.org | D3A852A27B |
Agent Smith | void16@null.org | CBCGAC92D7 |
Agent Smith | void17@null.org | B63D21E092 |
Agent Smith | void18@null.org | 0F3BF3BCE4 |
Agent Smith | void19@null.org | 9GC96D10G8 |
Agent Smith | void20@null.org | E4C42E72A1 |
Agent Smith | void21@null.org | 7E69CC7720 |
Agent Smith | void22@null.org | 6AC670680A |
Agent Smith | void23@null.org | GF9CF32419 |
Agent Smith | void24@null.org | 9F0197ADD6 |
Agent Smith | void25@null.org | 0C0GGEEB45 |
Agent Smith | void26@null.org | 49D3110A62 |
Agent Smith | void27@null.org | 5649825CF1 |
Agent Smith | void28@null.org | BGD43AAD05 |
Agent Smith | void29@null.org | 8928280285 |