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

Taro.pageScrollTo 滚动位置不准确 #16609

Open
shi-thething opened this issue Sep 27, 2024 · 0 comments
Open

Taro.pageScrollTo 滚动位置不准确 #16609

shi-thething opened this issue Sep 27, 2024 · 0 comments

Comments

@shi-thething
Copy link

相关平台

H5

复现仓库

https://github.com/shi-thething/taroTest.git
浏览器版本: Chrome 128
使用框架: React

复现步骤

必现问题

源码地址:
69行 - https://github.com/NervJS/taro/blob/main/packages/taro-h5/src/api/ui/scroll/index.ts

问题代码块:
const scroll = (frame = 0) => {
const dest = from delta * easeFunc(frame)
scrollFunc(dest) <---------------------此处是问题代码
if (frame < frameCnt) {
timer && clearTimeout(timer)
timer = setTimeout(() => {
scroll(frame 1)
}, FRAME_DURATION)
} else {
return handle.success({}, { resolve, reject })
}
}

问题:
设置top时,变量 frame 的正确取值范围是 0 - (frameCnt -1)
在最后一次循环调用时rame === frameCnt,easeFunc(frame)的值会大于1,导致dest的值比期望值多了一帧的量

解决方案: scrollFunc(dest)的执行,应该移动到 if (frame < frameCnt) 条件内部

期望结果

滚动准确

实际结果

滚动偏差,多滚动了一帧

环境信息

👽 Taro v3.6.23


  Taro CLI 3.6.23 environment info:
    System:
      OS: macOS 14.6.1
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 16.20.2 - /usr/local/bin/node
      npm: 8.19.4 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.23 => 3.6.23 
      @tarojs/components: 3.6.23 => 3.6.23 
      @tarojs/helper: 3.6.23 => 3.6.23 
      @tarojs/plugin-framework-react: 3.6.23 => 3.6.23 
      @tarojs/plugin-platform-alipay: 3.6.23 => 3.6.23 
      @tarojs/plugin-platform-h5: 3.6.23 => 3.6.23 
      @tarojs/plugin-platform-jd: 3.6.23 => 3.6.23 
      @tarojs/plugin-platform-qq: 3.6.23 => 3.6.23 
      @tarojs/plugin-platform-swan: 3.6.23 => 3.6.23 
      @tarojs/plugin-platform-tt: 3.6.23 => 3.6.23 
      @tarojs/plugin-platform-weapp: 3.6.23 => 3.6.23 
      @tarojs/react: 3.6.23 => 3.6.23 
      @tarojs/runtime: 3.6.23 => 3.6.23 
      @tarojs/shared: 3.6.23 => 3.6.23 
      @tarojs/taro: 3.6.23 => 3.6.23 
      @tarojs/taro-loader: 3.6.23 => 3.6.23 
      @tarojs/webpack5-runner: 3.6.23 => 3.6.23 
      babel-preset-taro: 3.6.23 => 3.6.23 
      eslint-config-taro: 3.6.23 => 3.6.23 
      react: ^18.0.0 => 18.3.1 
This was referenced Sep 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant