Giter Site home page Giter Site logo

infinite's Introduction

infinite Bitdeli

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

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

infinite's People

Contributors

buschtoens avatar vendethiel avatar

Stargazers

William Goulart avatar Gál Tamás avatar NIIDATE Kunitaka avatar Qasim Seeha avatar  avatar Jonathan Barratt avatar  avatar Ian Storm Taylor avatar  avatar Kitsion avatar Troy Therrien avatar Nick Thompson avatar Milos Janjic avatar Corentin Kerisit avatar PG Herveou avatar Larry Zhao avatar Cristian Douce avatar Stepan Anchugov avatar Xiao Jia avatar Aldo Nievas avatar Dan Zajdband avatar Pierce Moore avatar  avatar Steven Fusco avatar TJ Holowaychuk avatar Julian Gruber avatar

Watchers

Nihad Abbasov avatar  avatar James Cloos avatar Douglas Counts avatar  avatar

infinite's Issues

is broken

Currently tried with my app, never fired.

> var el = document.getElementById('polls');
undefined
> [el.scrollHeight, el.scrollTop, el.clientHeight]
[321, 0, 321]

Unbind from the DOM

As per #2 it would be pretty useful to destroy an infinite instance once and for all, so that no unnecessary event listener is left on the DOMElement.

Probably infinite.unbind() is a good name. infinite.bind(el) should be added in as well. Just to be consistent.

Optionally use mousewheel event

As per #2 infinite doesn't work for non-overflowing elements. The user should have the ability to opt for the mousewheel event, so he may do things like caroussels, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.