pull-refresh.js
1.48 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
var $ = require('yoho-jquery'),
IScroll = require('yoho-iscroll/build/iscroll-probe');
// 下拉刷新,上滑加载插件
// 参数一选择器,参数二选项
// height:容器高度
// pullDown:下拉回调
// pullUp:上滑回调
// 示例代码:
// new PullRefresh('.star-wrap', {
// height: $(window).height() - $('#yoho-header').height() - $('.head-tab').height(),
// pullDown: function() {
// console.log('下拉了');
// },
// pullUp: function() {
// console.log('上滑了');
// }
// });
function PullRefresh(seclector, options) {
var $window = $(window),
$em,
pullFormTop = false,
pullStart;
$em = $(seclector);
if (!$em.length) {
return;
}
if (options.height) {
$em.height(options.height);
}
this.iScroll = new IScroll($em.get(0), {
click: true,
bounce: false,
probeType: 3
});
this.iScroll.on('scrollStart', function() {
if (this.y === 0) {
pullFormTop = true;
}
pullStart = this.y;
$window.trigger('scroll');
});
this.iScroll.on('scrollEnd', function() {
if (pullFormTop && this.directionY === -1) {
options.pullDown && options.pullDown();
}
pullFormTop = false;
if (pullStart === this.y && this.directionY === 1) {
options.pullUp && options.pullUp();
}
$window.trigger('scroll');
});
}
module.exports = PullRefresh;