提交 b412c43b 编写于 作者: D DCloud_LXH

fix: createIntersectionObserver rectify intersectionRatio

上级 af9edeeb
......@@ -19,6 +19,22 @@ function getRect (rect) {
}
}
// 在相交比很小的情况下,Chrome会返回相交为0
function rectifyIntersectionRatio(entrie) {
const {
intersectionRatio,
boundingClientRect: { height: overAllHeight, width: overAllWidth },
intersectionRect: { height: intersectionHeight, width: intersectionWidth },
} = entrie
if (intersectionRatio !== 0) return intersectionRatio
return intersectionHeight === overAllHeight
? intersectionWidth / overAllWidth
: intersectionHeight / overAllHeight
}
const intersectionObservers = {}
export function requestComponentObserver ({
......@@ -44,7 +60,7 @@ export function requestComponentObserver ({
UniViewJSBridge.publishHandler('onRequestComponentObserver', {
reqId,
res: {
intersectionRatio: entrie.intersectionRatio,
intersectionRatio: rectifyIntersectionRatio(entrie),
intersectionRect: getRect(entrie.intersectionRect),
boundingClientRect: getRect(entrie.boundingClientRect),
relativeRect: getRect(entrie.rootBounds),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册