1.功能概览
这里有三个Tab,点击切换后,滚动条需要滚动到指定的位置,这里需要用到下面的方法
1.scroll-view 方法 小程序scroll-view 方法
需要在页面上加上scroll-view 标签
<scroll-view class="browse_content_box" scroll-y="true" style="height:100%" scroll-top="{{scrllorTop}}">
//scroll-y 允许纵向滑动
//scroll-top 设置竖向滚动条位置
//style="height:100%" //设置高度和父级一样
2.每次点击取到下标和标签商店ID,获取元素高度
let scrollName = ""
if(index == 0){
scrollName = '#singleId'
}else if (index == 1){
scrollName = '#manyId'
}else if (index == 2){
scrollName = '#judgeId'
}
const query = wx.createSelectorQuery()
query.select(scrollName).boundingClientRect()
query.selectViewport().scrollOffset()
query.exec(function(res){
console.log(res)
let scrollTop = res[0].top
that.setData({
scrllorTop :scrollTop
})
res[0].top // #the-id节点的上边界坐标
res[1].scrollTop // 显示区域的竖直滚动位置
})
3.功能展示