javascript
// 如下:
<template>
<div id="home">
<div v-for="(item, index) in list" :key="index" @click="onClick(item, index)">
<div :id="'node' + index"></div>
</div>
</div>
</template>
点击元素后
javascript
const id = `#node${index}`
uni.createSelectorQuery().in(this).select(id).boundingClientRect((data) => {
uni.createSelectorQuery().select('#home').boundingClientRect((res) => {
// console.log('node', data.top)
// console.log('home', res.top)
uni.pageScrollTo({
scrollTop: data.top - res.top - 200,
duration: 300,
})
}).exec()
}).exec()