Created
June 13, 2017 04:16
-
-
Save Leask/57f4de2291e2084aa360801bc6def94d to your computer and use it in GitHub Desktop.
Endless Scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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