给需要滚到特定位置的元素或者组件添加一个id,通过这个id值可确定位置数据,具体代码如下:
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});});