Skip to content

Instantly share code, notes, and snippets.

@Leask
Created June 13, 2017 04:16
Show Gist options
  • Save Leask/57f4de2291e2084aa360801bc6def94d to your computer and use it in GitHub Desktop.
Save Leask/57f4de2291e2084aa360801bc6def94d to your computer and use it in GitHub Desktop.
Endless Scroll
var fakeAjax = function(url, success, fail) {
setTimeout(function() {
console.log('Done!!!');
success();
}, 1000);
};
var render = function() {
$('.cloud-Label ul.clearFix').append('<li>anything</li>');
};
var $windowSL = $(window);
var $document = $(document);
var appendLock = false;
var append = function() {
if (appendLock) {
return;
}
appendLock = true;
console.log('refresh');
fakeAjax('xxx', function() {
appendLock = false;
for (var i = 0; i < 10; i++) {
render();
}
}, function() {
appendLock = false;
});
};
$windowSL.on('scroll', function() {
if ($windowSL.scrollTop() + $windowSL.height() >= $document.height()) {
append();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment