Scroll infinitely and get new content from a callback function
By default infinite
listens on the scroll
event. If the element
has no scrollbars, infinite
will run on each mousewheel
event.
$ component install silvinci/infinite
var infinite = require("infinite");
infinite(document.querySelector("ul"), function(iteration) {
var self = this;
request("/data?p=" + iteration, function(data) {
var li = document.createElement("li")
, text = document.createTextNode(data);
li.appendChild(text);
self.appendChild(li);
});
});
Listen for scroll events on el
. Call loadCallback
, when the
scrollbar of el
hits the end. Optionally specify a margin
so that loadCallback
gets called before the scrollbar hits
the end.
Manually issue a scrollevent, triggering loadCallback
, if the
scrollbar is in the margin or at the end.
Emitted each time the user scrolls inside the margin.
The callback is called with this
as el
and the arguments
iteration
which counts how often the callback was called (starting at 0
)
and delta
which returns the delta to the previous state (-1
or 1
).
Stop emitting load
events.
Resume emitting load
events.
Listen for events on the given element
. Will unregister all events from an
element that may have been registered previously.
Unbind from the event, virtually deconstructing this instance of Infinite
.
MIT