Skip to content

Commit

Permalink
fix: 🐛 taro-h5 处理IntersectionObserver初始化不触发回调的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
BonjourBernard committed Oct 15, 2024
1 parent 5148dd6 commit 9f7bcd7
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit 9f7bcd7

Please sign in to comment.