fixed endlessscroll

This commit is contained in:
Flummi 2016-09-05 08:40:11 +00:00
parent 06e41006a2
commit beb738f657
2 changed files with 16 additions and 19 deletions

View File

@ -13,27 +13,22 @@
</ul>
<script src="./s/jquery-3.1.0.min.js"></script>
<script>
var scrollListener = () => {
$(window).one("scroll", () => {
if($(window).scrollTop() + 256 >= $(document).height() - $(window).height()) {
$.ajax({
url: './api/p/'+$('#posts').data('last'),
dataType: 'json',
success: (msg) => {
var html = "";
for(var i = 0; i < msg.items.length; i++)
if(msg.items[i].id)
html += "<li class=\"post\"><a href=\"//f0ck.me/"+msg.items[i].id+"\" title=\""+msg.items[i].mime+"\"><img class=\"thumb\" src=\"//f0ck.me/t/"+msg.items[i].id+".png\" /></a></li>\n";
$('#posts').append(html);
$('#posts').data('last', msg.last);
}
var load = false;
$(function() {
$(window).scroll(() => {
if($(window).scrollTop() + $(window).height() == $(document).height() && !load) {
load = true;
$.getJSON('./api/p/'+$('#posts').data('last'), (msg) => {
var html = "";
for(var i = 0; i < msg.items.length; i++)
if(msg.items[i].id)
html += "<li class=\"post\"><a href=\"//f0ck.me/"+msg.items[i].id+"\" title=\""+msg.items[i].mime+"\"><img class=\"thumb\" src=\"//f0ck.me/t/"+msg.items[i].id+".png\" /></a></li>\n";
$('#posts').append(html);
$('#posts').data('last', msg.last);
load = false;
});
}
setTimeout(scrollListener, 200);
});
};
$(document).ready(() => {
scrollListener();
});
</script>
</body>

View File

@ -21,7 +21,8 @@ ul#posts {
display: flex;
-webkit-flex-flow: row wrap;
flex-flow: row wrap;
justify-content: space-between;
justify-content: flex-start;
-webkit-justify-content: flex-start;
}
li.post {
padding: 5px;
@ -30,6 +31,7 @@ li.post {
margin-top: 5px;
line-height: 128px;
-webkit-flex: 1 1 auto;
ms-flex: 1 1 auto;
flex: 1 1 auto;
}
.thumb {