dcloudio / dcloudio/uni-app

uni.pageScrollTo页面滚动的BUG

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

Description

**问题描述**
使用uni.pageScrollTo在移动端H5的页面滚动时,输入的duration为0时、scrollTop不为0,页面不会滚动到目标位置,而是直接滚动到顶部
**复现步骤**
如上描述
uni.pageScrollTo({
scrollTop: 300,
duration: 0,
success(res) {
console.log('scroll res------>', res)
},
fail(err) {
console.log('err------>', err);
},
complete(end) {
console.log('end------>', end);
}
});
**预期结果**
页面滚动到目标位置
**实际结果**
页面滚动到顶部

**系统信息:**
- 发行平台: [H5平台]

**补充信息**
源码中判断滚动的大小,以及滚动的元素判断,是否需要兼容移动端,毕竟移动端和PC端滚动的元素类型不一样,是否做一下兼容处理?
var scrollTop = _ref.scrollTop,
duration = _ref.duration;
var documentElement = document.documentElement;
var clientHeight = documentElement.clientHeight,
scrollHeight = documentElement.scrollHeight;
scrollTop = Math.min(scrollTop, scrollHeight - clientHeight);

if (duration === 0) {
// 部分浏览器(比如微信)中 scrollTop 的值需要通过 document.body 来控制
documentElement.scrollTop = document.body.scrollTop = scrollTop;
return;
}

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.