Skip to content

Instantly share code, notes, and snippets.

@tnantoka
Created October 15, 2011 13:31
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 tnantoka/1289561 to your computer and use it in GitHub Desktop.
Save tnantoka/1289561 to your computer and use it in GitHub Desktop.
Call fn when scroll on the bottom of page
function onBottom(fn) {
window.addEventListener('scroll', function() {
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
var scrollHeight = /*document.body.scrollHeight ||*/ document.documentElement.scrollHeight;
var clientHeight = /*document.body.clientHeight ||*/ document.documentElement.clientHeight;
var remain = scrollHeight - (clientHeight + scrollTop);
if (remain == 0) {
fn();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment