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>8831GB8BAA</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>33F5CDD1GG</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>F67G8E5F6C</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>B9...
Name | ID | |
---|---|---|
Agent Smith | void10@null.org | 8831GB8BAA |
Agent Smith | void11@null.org | 33F5CDD1GG |
Agent Smith | void12@null.org | F67G8E5F6C |
Agent Smith | void13@null.org | B9G36AC213 |
Agent Smith | void14@null.org | 8C47A38256 |
Agent Smith | void15@null.org | 94GF3A1844 |
Agent Smith | void16@null.org | 9D9A72D54B |
Agent Smith | void17@null.org | 2E63EAE310 |
Agent Smith | void18@null.org | 3CC5742E41 |
Agent Smith | void19@null.org | 0C82978B28 |
Agent Smith | void20@null.org | 01GF4BD088 |
Agent Smith | void21@null.org | A893GD7C2C |
Agent Smith | void22@null.org | B3EGD4C333 |
Agent Smith | void23@null.org | 2E051C1EA2 |
Agent Smith | void24@null.org | EFE116DE1C |
Agent Smith | void25@null.org | CDDF8C61F7 |
Agent Smith | void26@null.org | 1E76332AC9 |
Agent Smith | void27@null.org | D9B45678GD |
Agent Smith | void28@null.org | 8FD72A9E2B |
Agent Smith | void29@null.org | B83787AFGB |