微信小程序的按钮点击后滚动到页面内的指定位置。
wxml内容
<view class="box1" bindtap="toComment">查看回答</view>//...其他内容<view class="box2 text-bold" id="comment">回答</view>
js内容
toComment() {var query = wx.createSelectorQuery()//创建节点查询器query.select('#comment').boundingClientRect()//选择id为comment的节点并查询的它布局位置query.exec(function(res) {//执行请求wx.pageScrollTo({scrollTop: res[0].top,//滚动到页面节点的上边界坐标duration: 300 // 滚动动画的时长});})},