Skip to content

Commit 7f7a887

Browse files
author
Daniel Schmidt
committed
Remove usage of isIntersecting, doesn't handle threshold
1 parent 0f1feb9 commit 7f7a887

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/intersection.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,15 @@ export function unobserve(element) {
6363

6464
function onChange(changes) {
6565
changes.forEach(intersection => {
66+
console.log(intersection)
6667
if (INSTANCE_MAP.has(intersection.target)) {
6768
const { callback, visible, threshold } = INSTANCE_MAP.get(
6869
intersection.target,
6970
)
70-
let inView
71-
if (typeof intersection.isIntersecting === 'boolean') {
72-
// Use the new "isIntersecting" property if available.
73-
inView = intersection.isIntersecting
74-
} else {
75-
// Trigger on 0 ratio only when not visible.
76-
inView = visible
77-
? intersection.intersectionRatio > threshold
78-
: intersection.intersectionRatio >= threshold
79-
}
71+
// Trigger on 0 ratio only when not visible.
72+
const inView = visible
73+
? intersection.intersectionRatio > threshold
74+
: intersection.intersectionRatio >= threshold
8075

8176
INSTANCE_MAP.set(intersection.target, {
8277
callback,

stories/Observer.story.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ storiesOf('Intersection Observer', module)
3838
</Observer>
3939
</ScrollWrapper>
4040
))
41+
.add('With threshold 50%', () => (
42+
<ScrollWrapper>
43+
<Observer threshold={0.5} onChange={action('Child Observer inview')}>
44+
{inView => (
45+
<Header>{`Header is fully inside the viewport: ${inView}`}</Header>
46+
)}
47+
</Observer>
48+
</ScrollWrapper>
49+
))
4150
.add('Trigger once', () => (
4251
<ScrollWrapper>
4352
<Observer

0 commit comments

Comments
 (0)