onVisibility 原先只调 schedule(),不重新测量。后台期间若发生尺寸变化 (横竖屏切换、系统字体缩放、页面布局重排),overflow 仍是旧值, 长文本的滚动距离会算错,表现为「还没滚完就翻页」或「滚过头留白」, 而 measure() 本身只在挂载和 resize 时执行。 改为回到前台先 measure() 再 schedule(),与 resize 处理保持一致。 审查同类边界,以下均已正确处理,未改动: - items 为空:模板用 v-if="current" 不渲染 - 只有 1 条且不溢出:schedule 直接 return,不空转定时器 - items 长度变化:watch 中把越界索引归零 - 滚动时长:Math.min(9, Math.max(3, ...)) 有上下限, 不会出现 NaN/Infinity 导致 setTimeout 异常 npm run build 与 vue-tsc 均通过。
This commit is contained in:
@@ -74,8 +74,14 @@ watch(
|
||||
)
|
||||
|
||||
function onVisibility() {
|
||||
if (document.visibilityState === 'visible') schedule()
|
||||
else clearTimer()
|
||||
if (document.visibilityState === 'visible') {
|
||||
// 回到前台时重新测量:后台期间可能发生过尺寸变化(横竖屏切换、
|
||||
// 系统字体缩放等),若沿用旧的 overflow,长文本的滚动距离会算错,
|
||||
// 出现「还没滚完就翻页」或「滚过头留白」。
|
||||
void measure().then(schedule)
|
||||
} else {
|
||||
clearTimer()
|
||||
}
|
||||
}
|
||||
|
||||
function openAll() {
|
||||
|
||||
Reference in New Issue
Block a user