GithubHelp home page GithubHelp logo

artsy / jquery-on-infinite-scroll Goto Github PK

View Code? Open in Web Editor NEW
3.0 40.0 4.0 9 KB

Callback when you reach the bottom of the page and ajax requests finish. Useful as an infinite scroll callback.

License: MIT License

JavaScript 58.14% Makefile 2.24% HTML 39.62%

jquery-on-infinite-scroll's Introduction

jQuery.onInfiniteScroll

Callback when you reach the bottom of the page and ajax requests finish. Useful as an infinite scroll callback.

Example

$.onInfiniteScroll(function() {
    // Fetch & append some content
});

$.onInfiniteScroll(function() {
    // Pass an optional offset from the page bottom at which to trigger the callback.
}, { offset: 100 });

// Remove the event listeners.
$.destroyInfiniteScroll();

Contributing

Please fork the project and submit a pull request with tests. Install node modules npm install and run tests with make test.

License

MIT

jquery-on-infinite-scroll's People

Contributors

craigspaeth avatar mzikherman avatar

Stargazers

Daniel (dB.) Doubrovkine avatar Muhamad Zulfiqor avatar AMT avatar

Watchers

Joey Aghion avatar Pavlos Vinieratos avatar Brennan Moore avatar Anandaroop Roy avatar Andre Rocha avatar Oksana avatar Daniel (dB.) Doubrovkine avatar Fladson Gomes avatar  avatar Caroline Lau avatar Carter Cleveland avatar Sepand Ansari avatar Devang Thakkar avatar Chung-Yi Chi avatar James Cloos avatar Dejan avatar Ashkan Nasseri avatar Anson Wang avatar  avatar  avatar Sarah Weir avatar Nikita Skalkin avatar Ole avatar Christina avatar Lily Pace avatar Samuel Rozenberg avatar Joel Rosenblatt avatar  avatar Nick Spinazze avatar Jacqueline Potts avatar Emma Dickson avatar  avatar Carlos avatar Tam avatar Kizito Egeonu avatar Danger avatar Sultan Al-Maari avatar TanjieM avatar  avatar Adam Iskounen avatar

jquery-on-infinite-scroll's Issues

Flank-triggered, not level-triggered

tl;dr: this module seems to be flank-triggered, not level-triggered, which leads to the usual problem, i.e., missing updates when there is no 'flank' (here: scroll event).

This error can be triggered in two different scenarios:

  1. On page load, there's less than a screenful of content. Nothing triggers at that point, and since there's no way to scroll, jquery-on-infinite-scroll never triggers at all. In case you're tempted to say "well, just load more than one screenful then", let me tell you: that's kinda what I intended to use this plugin for. Temporary workaround for me: well, just load more than one screenful then.
  2. When scrolling extremely fast, it seems to be possible to trigger precisely one event. My callback loads precisely one more cell of a table, so sometimes my callback doesn't change the height of the overall document. If this happens, and the user already has reached the bottom, then jquery-on-infinite-scroll doesn't notice that after my callback completes, the user is still at the bottom. Temporary workaround for me: load enough new elements so that I know I add height to the overall document.

Suggested fix (both actions necessary, as far as I can see):

  1. Inside .onInfiniteScroll, run your check the first time. Don't wait for a user action. There are people with huge screens, y'know.
  2. After running the callback, re-run the check currently in onScroll. As this might change behavior for other people, there's two ways to go about this:
    • too bad for other people. Tell them to fix their code, and re-run the check unconditionally.
    • recognize a new option, something like recheck, so that a call could look like this: $.onInfiniteScroll(myFn, { offset: 50, recheck: true });

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.