index.js
1.02 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
Component({
properties: {
defaultIndex: { // 默认选中位置
type: Number,
value: 0
},
navs: { // [{name: '', id: ''}]
type: Array,
value: []
}
},
data: {
scrollLeft: 0
},
ready: function() {
setTimeout(() => {
if (this.data.navs.length > 3) {
let systemInfo = wx.getSystemInfoSync();
wx.createSelectorQuery().in(this).select('.my-scroll-nav .nav-item.active').boundingClientRect().exec(res => { // eslint-disable-line
let offset = res[0] || {};
this.setData({
scrollLeft: offset.left - systemInfo.windowWidth / 2 + offset.width / 2
});
});
}
}, 200);
},
methods: {
tapNav: function(e) { // 滚动底部 加载更多 回调
let dataset = e.currentTarget.dataset;
this.triggerEvent('tapNav', {dataset});
}
}
});