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

H5 中 query.selectViewport().scrollOffset() 的 scrollTop 始终返回 0 #7553

Closed
yuezk opened this issue Sep 8, 2020 · 0 comments · Fixed by #11033
Closed

H5 中 query.selectViewport().scrollOffset() 的 scrollTop 始终返回 0 #7553

yuezk opened this issue Sep 8, 2020 · 0 comments · Fixed by #11033
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x

Comments

@yuezk
Copy link
Contributor

yuezk commented Sep 8, 2020

相关平台

H5

复现仓库

https://github.com/yuezk/taro_bug
浏览器版本: Chrome 84
使用框架: React

复现步骤

  1. 进入 h5_selectViewport 目录
  2. 运行 yarn install && yarn dev:h5
  3. 在打开的页面中,点击底部的 Call query.selectViewport().scrollOffset() 按钮,会弹出当前页面的 scrollTop 的值,为 0
  4. 向下滚动页面,再次点击该按钮,弹出的值仍然是 0

期望结果

正确的 scrollTop 的值

实际结果

一直是 0

环境信息

❯ taro info           
👽 Taro v3.0.5


  Taro CLI 3.0.5 environment info:
    System:
      OS: macOS 10.15.5
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 12.14.1 - /usr/local/bin/node
      npm: 6.13.4 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.0.5 => 3.0.5 
      @tarojs/mini-runner: 3.0.5 => 3.0.5 
      @tarojs/react: 3.0.5 => 3.0.5 
      @tarojs/runtime: 3.0.5 => 3.0.5 
      @tarojs/taro: 3.0.5 => 3.0.5 
      @tarojs/webpack-runner: 3.0.5 => 3.0.5 
      babel-preset-taro: 3.0.5 => 3.0.5 
      eslint-config-taro: 3.0.5 => 3.0.5 
      react: ^16.10.0 => 16.13.1 

补充信息

现在由于 .taro_tabbar__panel 变成了可以滚动的容器 (#7435),html 标签变成了不滚动的了,调 query.selectViewport().scrollOffset() 拿到的 scrollTop 的值始终是 0,为了兼容,目前只能写成下面这样:

if (process.env.TARO_ENV === 'h5') {
    query.select('.taro-tabbar__panel').scrollOffset();
} else {
    query.selectViewport().scrollOffset();
}
@taro-bot2 taro-bot2 bot added F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x labels Sep 8, 2020
@yuezk yuezk changed the title query.selectViewport().scrollOffset() 不能返回期望的值 H5 中,query.selectViewport().scrollOffset()scrollTop 始终返回 0 Sep 8, 2020
@yuezk yuezk changed the title H5 中,query.selectViewport().scrollOffset()scrollTop 始终返回 0 H5 中 query.selectViewport().scrollOffset() 的 scrollTop 始终返回 0 Sep 8, 2020
ZakaryCode added a commit that referenced this issue Jan 4, 2022
ZakaryCode added a commit that referenced this issue Jan 6, 2022
ZakaryCode added a commit that referenced this issue Jan 6, 2022
(cherry picked from commit 4164792)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-h5 Target - 编译到 H5 V-3 Version - 3.x
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant