index.js
1.67 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
import wx from '../../utils/wx';
Component({
properties: {
isTop: { // 是否展示返回顶部按钮
type: Boolean,
value: false
},
isShare: { // 是否显示分享
type: Boolean,
value: false
}
},
data: {
isTopShow: true,
indicatorAnimation: {},
height: 0,
scrollTop: 0
},
ready: function() {
let systemInfo = wx.getSystemInfoSync();
this.setData({height: systemInfo.windowHeight});
},
methods: {
tapComponentsMore: function() { // 滚动底部 加载更多 回调
this.triggerEvent('tapLoadMore', {});
},
backToTop: function() { // 返回顶部
this.setData({scrollTop: 0});
},
onScroll: function(e) {
if (this.data.isTop) { // 返回顶部按钮显示 不显示控制
let { scrollTop } = e.detail || {};
let isTopShow = scrollTop > this.data.height * 2 ? true : false;
if (isTopShow !== this.data.isTopShow) {
let animtionIndicator = wx.createAnimation({
duration: 300,
timingFunction: 'linear',
});
if (isTopShow) {
animtionIndicator.opacity(1).step();
} else {
animtionIndicator.opacity(0).step();
}
this.setData({
indicatorAnimation: animtionIndicator.export(),
isTopShow: isTopShow
});
}
}
}
}
});