-
Notifications
You must be signed in to change notification settings - Fork 0
/
infinitescroller.js
45 lines (38 loc) · 971 Bytes
/
infinitescroller.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
(function(window, $, undefined) {
$.fn.infinitescroller = function(options) {
if (!this.length) { return this; }
var opts = $.extend(true, {}, $.fn.infiniteScroller.defaults, options);
var $this = $(this);
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height() + opts.bufferPix ) {
$.ajax({
url: opts.url,
type: 'GET',
dataType: opts.datatype,
data: {id: $('.post:last').attr('id')},
success: function(data, textStatus, xhr) {
if(data){
$this.append(data);
}
if (opts.callback typeof "function") {
opts.callback.call();
};
},
error: function(xhr, textStatus, errorThrown) {
if(opts.debug){
console.error(xhr);
}
}
});
};
});
return this;
};
$.fn.infinitescroller.defaults = {
url: "page/",
bufferPix: 40,
debug: false,
datatype: 'html'
callback: function(){}
};
})(window, jQuery);