https://github.com/buschtoens/infinite
Scroll infinitely and get new content from a callback function
https://github.com/buschtoens/infinite
Last synced: 3 months ago
JSON representation
Scroll infinitely and get new content from a callback function
- Host: GitHub
- URL: https://github.com/buschtoens/infinite
- Owner: buschtoens
- Created: 2013-01-10T14:09:43.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T08:57:41.000Z (almost 2 years ago)
- Last Synced: 2025-04-23T16:08:08.365Z (6 months ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 25
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# infinite 
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.## Installation
```
$ component install silvinci/infinite
```
## Example```javascript
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);
});
});
```## API
### Infinite(el, loadCallback, [margin])
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.### Infinite.onscroll()
Manually issue a scrollevent, triggering `loadCallback`, if the
scrollbar is in the margin or at the end.### Infinite.on("load", function(iteration, delta) {});
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`).### Infinite.pause()
Stop emitting `load` events.
### Infinite.resume()
Resume emitting `load` events.
### Infinite.bind(element)
Listen for events on the given `element`. Will unregister all events from an
element that may have been registered previously.### Infinite.unbind()
Unbind from the event, virtually deconstructing this instance of `Infinite`.
## License
MIT