Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法获取document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop #2356

Closed
vurtnr opened this issue Mar 5, 2019 · 4 comments
Assignees
Labels
T-h5 Target - 编译到 H5 V-1 Version - 1.x V-2 Version - 2.x

Comments

@vurtnr
Copy link

vurtnr commented Mar 5, 2019

问题描述
h5端,需要手动实现tab吸顶效果,代码如下:
image
三个值永远是0,然后重新init一个空项目,在未在app.js中配置tabbar的情况下一切正常

复现步骤
空项目不配置tabbar情况下获取上述三个值其中之一.
同样的项目,app.js中配置tabbar,返回组件,重新获取三个值全部显示为0

期望行为

可以取到document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop 三个值中的一个

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。

  • 操作系统: [e.g. macOS 10.14.3]
  • Taro 版本 [e.g. v.1.2.12]
  • Node.js 版本 [e.g. v11.2.0]
  • 报错平台 [h5]
    image

补充信息
如果有变通的法子,请指导下如何在框架中使用。

@taro-bot
Copy link

taro-bot bot commented Mar 5, 2019

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@luckyadam luckyadam added the H5 label Mar 6, 2019
@taro-bot taro-bot bot assigned Littly Mar 6, 2019
@taro-bot
Copy link

taro-bot bot commented Mar 6, 2019

CC @Littly

@Littly
Copy link
Contributor

Littly commented Mar 6, 2019

感谢反馈,确实有这个情况,带 tabbar 的页面结构与平常的不太一样。比如,页面带tabbar的情况下,滚动容器会变成.taro-tabbar__panel了。在 Taro 内部暂时是通过比较原始的办法解决:

const getScroller = () => {
const panel = document.querySelector('.taro-tabbar__panel')
let res: {
set: (number) => void;
get: () => number;
}
if (panel) {
res = {
set: pos => { panel.scrollTop = pos },
get: () => panel.scrollTop
}
} else {
res = {
set: pos => window.scrollTo(0, pos),
get: () => window.pageYOffset
}
}
return res
}

我们后续想个更加优雅的解决办法,避免开发者需要过多地触及Taro内部的细节。

@vurtnr
Copy link
Author

vurtnr commented Mar 12, 2019

@Littly 你好,我现在是需要更新还是如何?

@Chen-jj Chen-jj added T-h5 Target - 编译到 H5 V-2 Version - 2.x and removed H5 enhancement New feature or request labels Jul 10, 2020
@ZakaryCode ZakaryCode added V-1 Version - 1.x V-2 Version - 2.x and removed V-2 Version - 2.x labels Aug 25, 2020
@ZakaryCode ZakaryCode moved this to Done in H5 Apr 10, 2023
@ZakaryCode ZakaryCode added this to H5 Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-h5 Target - 编译到 H5 V-1 Version - 1.x V-2 Version - 2.x
Projects
Archived in project
Development

No branches or pull requests

6 participants