微信小程序页面滚动到指定位置

页面上有一个元素或者组件,id 为 comment 

则:

var me = this;
      var query = wx.createSelectorQuery().in(me);
      query.selectViewport().scrollOffset()
      query.select("#comment").boundingClientRect();
      query.exec(function (res) {
        console.log(res);
        var miss = res[0].scrollTop + res[1].top - 10;
        wx.pageScrollTo({
          scrollTop: miss,
          duration: 300
        });
        
      });

  

猜你喜欢

转载自www.cnblogs.com/muamaker/p/11307902.html