Skip to content

Commit 4ab2dc8

Browse files
committed
Use isIntersecting when available
1 parent c1e1829 commit 4ab2dc8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/intersection.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ function onChange(changes) {
123123
const options = instance.options
124124

125125
let inView = false
126-
if (intersectionRatio < 0 && isIntersecting) {
127-
// Firefox bug, causes intersectionRatio to sometimes be less than zero if element is larger than viewport
128-
inView = true
126+
127+
if (isIntersecting !== undefined) {
128+
// If isIntersecting is defined, use it to confirm the intersection.
129+
// Firefox can report a negative intersectionRatio, but it will still have correctly set isIntersecting
130+
inView = isIntersecting
129131
} else if (Array.isArray(options.threshold)) {
130132
// If threshold is an array, check if any of them intersects. This just triggers the onChange event multiple times.
131133
inView = options.threshold.some(threshold => {
@@ -140,12 +142,6 @@ function onChange(changes) {
140142
: intersectionRatio >= options.threshold
141143
}
142144

143-
if (isIntersecting !== undefined) {
144-
// If isIntersecting is defined, ensure that the element is actually intersecting.
145-
// Otherwise it reports a threshold of 0
146-
inView = inView && isIntersecting
147-
}
148-
149145
// Update the visible value on the instance
150146
instance.visible = inView
151147

0 commit comments

Comments
 (0)