_getItemTop() {
let _this = this
let getDistance = []
let srocllArray = ['.name-top', '.phone-top', '.wxcode-top', '.location-top', '.region-top', '.wrokstatus-top', '.education-top', '.isfeed-top', '.haspet-top', '.service-top', '.oneproblem-top', '.twoproblem-top', '.threeproblem-top', '.fourproblem-top']
for (let i = 0, len = srocllArray.length; i < len; i++) {
wx.createSelectorQuery().select(srocllArray[i]).boundingClientRect(function(rect) {
if (srocllArray[i] === '.region-top') {
getDistance.push(rect.top - 50)
_this.setData({
allSrcoll: getDistance
})
}
getDistance.push(rect.top - 100)
_this.setData({
allSrcoll: getDistance
})
}).exec()
}
},
API wx.pageScrillTop() 使用
// nums为我数组 srocllArray 引用索引
_scorllTo(nums) {
let _this = this
wx.pageScrollTo({
scrollTop: _this.data.allSrcoll[nums],
duration: 300
})
},
最后在需要的地方调用传入相应的参数
this._scorllTo(0) //0就为scroll到class为.name-top的元素位置