Skip to content

Instantly share code, notes, and snippets.

@s-aska
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save s-aska/8fcef7cd18c02af8f09b to your computer and use it in GitHub Desktop.
Save s-aska/8fcef7cd18c02af8f09b to your computer and use it in GitHub Desktop.
(function (ns, w, d, $) {
'use strict';
var win = $(w);
var doc = $(d);
var autopager = function () {
setTimeout(function () {
if ((doc.height() - (win.scrollTop() + win.height())) < win.height()) {
doc.trigger('autopager');
} else {
autopager();
}
}, 1000);
};
ns.autopager = autopager;
})(this, window, document, jQuery);
@s-aska
Copy link
Author

s-aska commented Aug 6, 2014

Example

$(function () {
    var page = 1;
    $(document).on('autopager', function () {
        // some code
        if (hasNext) {
            page++;
            autopager(); // autopage event is one-time.
        }
    }).trigger('autopager');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment