File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed
Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -64,15 +64,21 @@ export function unobserve(element) {
6464function onChange ( changes ) {
6565 changes . forEach ( intersection => {
6666 if ( INSTANCE_MAP . has ( intersection . target ) ) {
67- const { callback, visible, threshold } = INSTANCE_MAP . get (
68- intersection . target ,
69- )
70- // Trigger on 0 ratio only when not visible.
71- const inView = visible
72- ? intersection . intersectionRatio > threshold
73- : intersection . intersectionRatio >= threshold
67+ const { isIntersecting, intersectionRatio, target } = intersection
68+ const { callback, visible, threshold } = INSTANCE_MAP . get ( target )
7469
75- INSTANCE_MAP . set ( intersection . target , {
70+ // Trigger on 0 ratio only when not visible. This is fallback for browsers without isIntersecting support
71+ let inView = visible
72+ ? intersectionRatio > threshold
73+ : intersectionRatio >= threshold
74+
75+ if ( isIntersecting !== undefined ) {
76+ // If isIntersecting is defined, ensure that the element is actually intersecting.
77+ // Otherwise it reports a threshold of 0
78+ inView = inView && isIntersecting
79+ }
80+
81+ INSTANCE_MAP . set ( target , {
7682 callback,
7783 visible : inView ,
7884 threshold,
You can’t perform that action at this time.
0 commit comments