ko-infinitescroll
KnockoutJS binding to handle infinite scrolling.
Usage
var todos = ko.observableArray([])
function fetchTodos() {
var ctx = this
ctx._page = ctx._page ? ++ctx._page : 1
return $.get('/todos', { page: ctx._page }, function(newTodos) {
todos.push.apply(todos, newTodos)
})
}
fetchTodos()
<div data-bind="foreach: todos, infiniteScroll: fetchToDos">
<div data-bind="template: { name: 'todo-template', data: $data }"></div>
</div>
or
<div data-bind="foreach: todos, infiniteScroll: { handler: fetchToDos, offset: 2000 }">
<div data-bind="template: { name: 'todo-template', data: $data }"></div>
</div>
In this second snippet, we specify a different offset (in px). Defaults to 1500px.
Depends on Knockout, jQuery, and Lodash
But you're using these already, right?