Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

ko-infinitescroll

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ko-infinitescroll

KnockoutJS Infinite Scroll Binding

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

ko-infinitescroll

KnockoutJS binding to handle infinite scrolling.

Usage

// in real life this would be a prop on your viewModel
var todos = ko.observableArray([])

function fetchTodos() {
  // `this` is the binding context
  var ctx = this

  ctx._page = ctx._page ? ++ctx._page : 1

  // Return promise so infinite scroll function can be disabled
  // until the call is resolved. If no promise is returned the
  // infinite scroll function is assumed to be synchronous
	return $.get('/todos', { page: ctx._page }, function(newTodos) {

    // append new todos
		todos.push.apply(todos, newTodos)
	})
}

// Load initial todos
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?

Keywords

knockoutjs

FAQs

Package last updated on 02 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts