data:{
header1:[‘小姐姐’,‘小姐姐’,‘小姐姐’],
scrollLeft:0,
scrollLeft1:0,
tit_id:0
},
getTit_Index(e){
let that=this
let header2=[]
this.setData({
tit_id:e.currentTarget.dataset.index,
})
this.scrollMoveTo_2(this.data.tit_id)
},
scrollMove(e) {
this.setData({scrollLeft: e.detail.scrollLeft});
},
scrollMoveTo(index) {
var that = this
wx.createSelectorQuery().select(’#item-’ + index).boundingClientRect(function (rect) {
console.log(rect);
let scrollLeft = that.data.scrollLeft;
console.log(‘old:’, scrollLeft);
if (rect.left < 0) {
scrollLeft = scrollLeft - (-rect.left + rect.width);
} else if (rect.right > app.systemInfo.windowWidth) {
scrollLeft = scrollLeft + rect.right - app.systemInfo.windowWidth
}
if (scrollLeft < 0) {
scrollLeft = 0;
}
console.log(‘new:’, scrollLeft);
that.setData({scrollLeft1: scrollLeft})
}).exec()
},
微信小程序点击tab栏自适应滚动
最新推荐文章于 2023-08-29 16:55:09 发布
{{item}}