无限滚动模式提供了一种在用户滚动操作时动态加载内容的方法。
¥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
- 当元素滚动到视口中时触发(对于延迟加载也很有用)。如果你在 css 中使用overflow
(如overflow-y: scroll
),则应使用intersect once
而不是revealed
。¥
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
.