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

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
        });
         
      });

 

let query = wx.createSelectorQuery().in(this);
query.selectViewport().scrollOffset()
query.select("#Nav").boundingClientRect();
query.select("#FilterNav").boundingClientRect();
query.select("#"+((letter=='#')?'other':letter)).boundingClientRect();
query.exec(function (res) {
    let scrollTop = 0;
    if(res[3]){
      scrollTop = res[0].scrollTop + res[3].top
    }else{
      scrollTop = res[0].scrollTop;
    }
    wx.pageScrollTo({
        scrollTop: scrollTop - res[1].height - res[2].height,
        duration: 300
    });
});
var that= this;
   var query = wx.createSelectorQuery().in(that);
   query.selectViewport().scrollOffset()
   query.select("#"+特定id值).boundingClientRect();
   query.exec(function (res) {
    console.log(res);
    var data= res[0].scrollTop + res[1].top - 10;   // 顶部距离该id值得距离
    wx.pageScrollTo({
     scrollTop: data,
     duration: 300
    });
   });

 

https://www.cnblogs.com/neeter/p/11990875.html
https://blog.csdn.net/rr123why/article/details/107685681


发表评论

电子邮件地址不会被公开。 必填项已用*标注