-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagingscroll.js
81 lines (63 loc) · 1.79 KB
/
pagingscroll.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
(function($) {
$.fn.scrollPagination = function(options) {
var settings = { // default setting
nop : 2,
offset : 0,
error : 'No More Posts!',
delay : 500,
clone : ''
}
if(options) {
$.extend(settings, options);
}
// For each so that we keep chainability.
return this.each(function() {
// Some variables
$this = $(this);
$settings = settings;
var offset = $settings.offset+$settings.nop;
var start = $settings.nop;
var busy = false;
var finish = false;
var $clone = $settings.clone;
function getData() {
$.ajax({
url:"index3.php",
success:function(result){
var data = JSON.parse(result);
if(offset>data.length){
console.log("Impossible Load, because data is empty");
console.log("Offset is:"+offset+" and Data size is:"+data.length);
offset = offset - $settings.nop; // return to current offset
var gapSize = data.length - offset; // get gap of size
offset = offset + gapSize;
console.log("Now Offset is:"+offset);
finish = true;
}
for(var i=start;i<offset;i++){
$clone.text(data[i].nama);
$clone.appendTo("article:eq(1)");
console.log(data[i].nama);
$clone = $clone.clone();
}
start = start + $settings.offset;
offset = offset + $settings.offset;
busy = false;
},
error:function(result){
console.log("Err: "+result);
}
});
}
getData(); // Run function initially
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > $this.height() && !busy) {
busy = true;
setTimeout(function() {
if(!finish){getData();}
}, $settings.delay);
}
});
});
}
})(jQuery);