dcloudio / dcloudio/uni-app

【bug】uni.pageScrollTo(selector)滚动定位的位置错误

Open
#4,928 3 comments 0 reactions 0 assignees View on GitHub
h5 vue2 提供了复现方案
Dominant language
JavaScript
Stars
41.6k
Forks
3.7k
Avg merge
7h 6m
Merged PRs (30d)
6

Description

### 版本信息
HbuilderX 4.15
uni-ui 1.5.0
### 代码片段
```




红凤凰粉凤凰红粉凤凰花凤凰




红鲤鱼与绿鲤鱼与驴




The quick brown fox jumps over the lazy dog




吃葡萄不吐葡萄皮








indexof 0



indexof 1



indexof 2





export default {
data() {
return {};
},
mounted() {
this.$refs.popup.open()
},
methods: {
handleScrollTo(value) {
uni.pageScrollTo({
selector: value,
success: (data) => {
console.log('success' + JSON.stringify(data))
},
fail: (data) => {
console.log('fail' + JSON.stringify(data))
}
})
}
},
}

.popup-wrapper {
width: 70vw;
padding: 20px 0 0 20px;
display: flex;
flex-direction: column;
height: 100%;

&-header {
padding-right: 20px;
font-size: 20px;
line-height: 1;
margin-bottom: 20px;
}

.scroll-Y {
max-height: calc(100vh - var(--window-top) - var(--window-bottom) - 40px);

::-webkit-scrollbar {
display: block;
width: 0 !important;
height: 0 !important;
background: transparent;
overflow: auto !important;
}

.catalog-body {
padding-bottom: 20px;

.catalog-item {
font-size: 20px;
line-height: 2.5;
}
}
}
}

```
### 复现步骤
点击indexof 0、indexof 1不会跳转,点击indexof2会跳转到id="main-box1"的位置

https://github.com/dcloudio/uni-app/assets/48954949/d07174dd-3fd1-421b-9097-8e1bc1ce6cf1

### 个人猜测
可能是滚动定位的位置计算了元素本身的高度。
如果将id放到内部的第一个元素,那么定位的位置就是该元素的高度。下面为该猜测的测试代码:
```
...


红鲤鱼与绿鲤鱼与驴


红鲤鱼与绿鲤鱼与驴




The quick brown fox jumps over the lazy dog


The quick brown fox jumps over the lazy dog




吃葡萄不吐葡萄皮


吃葡萄不吐葡萄皮


...
```

https://github.com/dcloudio/uni-app/assets/48954949/2cea9f5b-45df-413d-b546-1d9f8a239ba0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.