// 在你的 Vue 组件中
export default {
methods: {
getElementPosition() {
// 使用uni.createSelectorQuery创建选择器查询实例
const query = uni.createSelectorQuery().in(this);
// 获取元素的位置信息
query.select('.your-element-class') // 替换为你要获取位置信息的元素类名或选择器
.boundingClientRect(rect => {
// rect中包含了位置信息
console.log('元素位置信息:', rect);
// rect 包含了元素的位置、尺寸等信息
// rect.top, rect.bottom, rect.left, rect.right, rect.width, rect.height
})
.exec();
}
}
}
uniapp获取元素位置:top、bottom、left、right
最新推荐文章于 2024-05-30 18:01:37 发布