微信小程序实现滚动到指定位置

 
 

<view class="box1" bindtap="toComment">查看回答</view>

//...其他内容

<view class="box2 text-bold" id="comment">回答</view>

toComment() {

var query = wx.createSelectorQuery()//创建节点查询器query.select('#comment').boundingClientRect()//选择id为comment的节点并查询的它布局位置

   query.exec(function(res) {//执行请求

   wx.pageScrollTo({

      scrollTop: res[0].top,//滚动到页面节点的上边界坐标

     duration: 300 // 滚动动画的时长

});

})

扫描二维码关注公众号,回复: 14182963 查看本文章

},

猜你喜欢

转载自blog.csdn.net/qq_33769914/article/details/124955067