You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
Component({
|
|
/**
|
|
* 组件的属性列表
|
|
*/
|
|
properties: {
|
|
typeList: {
|
|
type: Array,
|
|
value: []
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 组件的初始数据
|
|
*/
|
|
data: {
|
|
scrollLeft: 0
|
|
},
|
|
|
|
/**
|
|
* 组件的方法列表
|
|
*/
|
|
methods: {
|
|
onButtonChange: function (e) {
|
|
const list = this.data.typeList
|
|
let that = this;
|
|
list.forEach(item => {
|
|
if (item.type === e.currentTarget.dataset.type) {
|
|
item.select = true
|
|
} else {
|
|
item.select = false
|
|
}
|
|
})
|
|
that.setData({
|
|
typeList: list,
|
|
})
|
|
var query = wx.createSelectorQuery().in(that);//创建节点查询器
|
|
query.select('#item-' + e.currentTarget.dataset.type).boundingClientRect();//选择id='#item-' + selectedId的节点,获取节点位置信息的查询请求
|
|
query.select('#scroll-view').boundingClientRect();//获取滑块的位置信息
|
|
query.select('#scroll-view').scrollOffset();//获取页面滑动位置的查询请求
|
|
query.exec(function (res) {
|
|
// console.log(res[2].scrollLeft + res[0].left + res[0].width / 2 - res[1].width / 2)
|
|
that.setData({
|
|
scrollLeft: res[2].scrollLeft + res[0].left + res[0].width / 2 - res[1].width / 2
|
|
});
|
|
});
|
|
this.triggerEvent('chooseType', e.currentTarget.dataset.type)
|
|
}
|
|
}
|
|
})
|
|
|