From 9f7bcd717ad16fe08c4483dbfb98673e683dafca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B8=E4=B9=98=E5=A3=B9?= <1926742214@qq.com> Date: Tue, 15 Oct 2024 17:52:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20taro-h5=20=E5=A4=84?= =?UTF-8?q?=E7=90=86IntersectionObserver=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E4=B8=8D=E8=A7=A6=E5=8F=91=E5=9B=9E=E8=B0=83=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-h5/src/api/wxml/IntersectionObserver.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/taro-h5/src/api/wxml/IntersectionObserver.ts b/packages/taro-h5/src/api/wxml/IntersectionObserver.ts index f6569bbc04f4..f05487eff08d 100644 --- a/packages/taro-h5/src/api/wxml/IntersectionObserver.ts +++ b/packages/taro-h5/src/api/wxml/IntersectionObserver.ts @@ -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) })