1.相关代码
gotoAnchor: function() { const query = wx.createSelectorQuery() query.select('.cart-evaluation').boundingClientRect() query.selectViewport().scrollOffset() query.exec(function(res){ res[0].top // #the-id节点的上边界坐标 res[1].scrollTop // 显示区域的竖直滚动位置 let distance = res[0].top + res[1].scrollTop wx.pageScrollTo({ scrollTop: distance }) }) }
参考链接:
https://developers.weixin.qq.com/miniprogram/dev/api/wxml/SelectorQuery.html
https://developers.weixin.qq.com/miniprogram/dev/framework/view/selector.html