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>07A4B0FEC2</td></tr>
<tr><td>Agent Smith</td><td>void11@null.org</td><td>726D94C703</td></tr>
<tr><td>Agent Smith</td><td>void12@null.org</td><td>AAD9AE592E</td></tr>
<tr><td>Agent Smith</td><td>void13@null.org</td><td>G0...
Name | ID | |
---|---|---|
Agent Smith | void10@null.org | 07A4B0FEC2 |
Agent Smith | void11@null.org | 726D94C703 |
Agent Smith | void12@null.org | AAD9AE592E |
Agent Smith | void13@null.org | G072CGBA3E |
Agent Smith | void14@null.org | C637C79B21 |
Agent Smith | void15@null.org | E8834331BD |
Agent Smith | void16@null.org | 4695BA9D97 |
Agent Smith | void17@null.org | A32856E46F |
Agent Smith | void18@null.org | DDDFGD921A |
Agent Smith | void19@null.org | 1593GEADEC |
Agent Smith | void20@null.org | 18C44CB430 |
Agent Smith | void21@null.org | A9A7D15141 |
Agent Smith | void22@null.org | G70GD82EC5 |
Agent Smith | void23@null.org | G62528CE5C |
Agent Smith | void24@null.org | FBE7F29E4F |
Agent Smith | void25@null.org | 04G91G8129 |
Agent Smith | void26@null.org | FE33CC55FE |
Agent Smith | void27@null.org | 4DCBF90E18 |
Agent Smith | void28@null.org | 65F6C3D1D5 |
Agent Smith | void29@null.org | 7F0FCA74E1 |