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

fix: 🐛 taro-h5 处理IntersectionObserver初始调用不触发回调的问题 #16716

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/taro-h5/src/api/wxml/IntersectionObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,14 @@ export class TaroH5IntersectionObserver implements Taro.IntersectionObserver {
// 使用时间戳而不是entry.time,跟微信小程序一致
time: Date.now(),
}

// web端会默认首次触发
if (!this._isInited && this._options.initialRatio <= Math.min.apply(Math, this._options.thresholds)) {
if (!this._isInited) {
// 初始的相交比例,如果调用时检测到的相交比例与这个值不相等且达到阈值,则会触发一次监听器的回调函数。
return
const [min, max] = [Math.min(this._options.initialRatio, entry.intersectionRatio), Math.max(this._options.initialRatio, entry.intersectionRatio)];
if(this._options.initialRatio === entry.intersectionRatio || !this._options.thresholds.some(value => value >= min && value <= max)) {
return
}
}
_callback && _callback.call(this, result)
})
Expand Down