页面滚动到指定dom的位置
// 1.使用wx.createSelectorQuery()查询到需要滚动到的元素位置
wx.createSelectorQuery().select('#bb4').boundingClientRect(res => {
console.log(res);
// 到这里,我们可以从res中读到class为bb4的top,即离顶部的距离(px)
// 2使用wx.pageScrollTo()将页面滚动到对应位置
wx.pageScrollTo({
scrollTop: res.top, // 滚动到的位置(距离顶部 px)
duration: 500 //滚动所需时间 如果不需要滚动过渡动画,设为0(ms)
})
}).exec()
浙公网安备 33010602011771号