forked from GermanTutorialsForPC/InfinitiScroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
infinityScroll.js
42 lines (37 loc) · 1.07 KB
/
infinityScroll.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var infinitiScroll = {
urlPrefix: "http://the.url.prefix/",
urlSuffix: "/the_suffix",
contentElement: "#content",
contentWrapper: ".contentWrapper",
pageNavigation: ".navigation"
};
const NAVIGATION_OFFSET = 100;
var nextPage = 2;
var loadingPage = false;
function infinitiScroll() {
if(!loadingPage) {
loadingPage = true;
$.get(infinitiScroll.urlPrefix + nextPage + infinitiScroll.urlSuffix, function(data){
$(data).find(infinitiScroll.contentElement).find(infinitiScroll.contentWrapper).appendTo(infinitiScroll.contentWrapper);
}).done(function(){
nextPage++;
loadingPage = false;
}).fail(function(){
$(infinitiScroll.pageNavigation).css({display: 'none'});
});
}
}
$(document).ready(function(){
$(infinitiScroll.pageNavigation + " a").click(function(){
infinitiScroll();
return false;
})
});
$(window).scroll(function(){
var positionNav = $(infinitiScroll.pageNavigation).offset().top;
var top = $(document).scrollTop();
var windowHeight = $(window).height();
if(top + windowHeight > positionNav - NAVIGATION_OFFSET) {
infinitiScroll();
}
});