data() {
return {
lineIndex: 0,
topList: []
}
}
getTopList(){
const query = uni.createSelectorQuery().in(this)
query.selectAll('.solls').boundingClientRect().exec((res) => {
let nodes = res[0]
let rel = [];
nodes.map(item => {
rel.push(item.top)
})
this.topList = rel
})
},
// 滑动到当前城市
getTopCity() {
uni.pageScrollTo({
duration: 100, //过渡时间
scrollTop: this.topList[this.lineIndex] - 80, //到达距离
})
},
主要内容:先获取到for上的class的高度,然后保存,在需要的地方调用