more-area.js
1.68 KB
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
const $ = require('jquery');
const lazyload = require('../plugins/lazyload');
window.jQuery = $;
let moreObj = {
domInit: function() {
this.el = {
$listContainer: $('#list-container')
};
},
init: function() {
this.domInit();
this.page = $('#currentPage').val() || 1;
this.loading = false;
this.end = false;
this.scroll();
},
scroll: function() {
$(window).scroll(() => {
if (($(window).scrollTop() + $(window).height() >= $(document).height() * 0.8)) {
this.doMore();
}
});
},
doMore: function() {
if (!this.loading && !this.end) {
this.page++;
this.getMore();
}
},
getMore: function() {
this.loading = true;
let ajaxData = {
page: this.page,
row: 10
};
if ($('#cityId').val()) {
Object.assign(ajaxData, {cityId: $('#cityId').val()});
}
$.ajax({
method: 'GET',
url: window.$ajaxPath,
data: ajaxData,
success: (result) => {
if ($(result).length > 0) {
let $result = $(result);
let $lazyImg = $result.find('img.lazy');
this.el.$listContainer.append($result);
lazyload($lazyImg, {
threshold: 1000,
q: 80
});
this.loading = false;
} else {
this.end = true;
}
}
});
}
};
$(
function() {
moreObj.init();
}
);