Skip to content

Commit 43ab993

Browse files
committed
only add resize listener for pixel offsets
1 parent 61c2f5a commit 43ab993

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Scrollama.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const TinyScrollama = props => {
1111
onStepExit,
1212
onStepProgress,
1313
} = props;
14-
14+
const isOffsetDefinedInPixels = isOffsetInPixels(offset)
1515
const [lastScrollTop, setLastScrollTop] = React.useState(0);
1616
const [windowInnerHeight, setWindowInnerHeight] = React.useState(null);
1717
const handleSetLastScrollTop = (scrollTop) => {
@@ -23,14 +23,16 @@ const TinyScrollama = props => {
2323
}
2424

2525
React.useEffect(() => {
26-
window.addEventListener('resize', handleWindowResize);
27-
return () => {
28-
window.removeEventListener('resize', handleWindowResize);
29-
};
26+
if(isOffsetDefinedInPixels) {
27+
window.addEventListener('resize', handleWindowResize);
28+
return () => {
29+
window.removeEventListener('resize', handleWindowResize);
30+
};
31+
}
3032
}, []);
3133

3234

33-
const offsetValue = isOffsetInPixels(offset)
35+
const offsetValue = isOffsetDefinedInPixels
3436
? (+offset.replace('px', '') / (windowInnerHeight || window.innerHeight))
3537
: offset;
3638

0 commit comments

Comments
 (0)