Skip to content

Instantly share code, notes, and snippets.

@s-aska s-aska/micro-autopager.js
Last active Aug 29, 2015

Embed
What would you like to do?
(function (ns) {
'use strict';
var autopager = function (callbackOnce) {
setTimeout(function () {
if (autopager.bottom()) {
callbackOnce.call();
} else {
autopager(callbackOnce);
}
}, 1000);
};
autopager.bottom = function () {
var documentHeight = Math.max(
document.body.scrollHeight,
document.body.offsetHeight,
document.documentElement.scrollHeight,
document.documentElement.offsetHeight,
document.documentElement.clientHeight
);
var windowHeight = window.document.documentElement.clientHeight;
var scrollTop = ('pageYOffset' in window) ? window.pageYOffset :
document.documentElement.scrollTop;
var invisibleHeight = documentHeight - windowHeight - scrollTop;
return invisibleHeight < windowHeight ? true : false;
};
ns.autopager = autopager;
})(this);
@s-aska

This comment has been minimized.

Copy link
Owner Author

s-aska commented Aug 6, 2014

Example

window.onload = function () {
  var loadpage = function () {
    // some code
    if (hasNext) {
      autopager(loadpage); // start autopage check.
    }
  };
  loadpage();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.