Skip to content

Commit 96b119f

Browse files
authored
Merge pull request #125 from SoundstripeTech/master
Fixed Chrome scroll issue
2 parents ac8581d + bd8a56a commit 96b119f

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

dist/InfiniteScroll.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ var InfiniteScroll = (function(_Component) {
117117
key: 'componentWillUnmount',
118118
value: function componentWillUnmount() {
119119
this.detachScrollListener();
120+
this.detachMousewheelListener();
120121
},
121122

122123
// Set a defaut loader for all your `InfiniteScroll` components
@@ -127,6 +128,21 @@ var InfiniteScroll = (function(_Component) {
127128
this.defaultLoader = loader;
128129
},
129130
},
131+
{
132+
key: 'detachMousewheelListener',
133+
value: function detachMousewheelListener() {
134+
var scrollEl = window;
135+
if (this.props.useWindow === false) {
136+
scrollEl = this.scrollComponent.parentNode;
137+
}
138+
139+
scrollEl.removeEventListener(
140+
'mousewheel',
141+
this.mousewheelListener,
142+
this.props.useCapture,
143+
);
144+
},
145+
},
130146
{
131147
key: 'detachScrollListener',
132148
value: function detachScrollListener() {
@@ -159,6 +175,11 @@ var InfiniteScroll = (function(_Component) {
159175
scrollEl = this.scrollComponent.parentNode;
160176
}
161177

178+
scrollEl.addEventListener(
179+
'mousewheel',
180+
this.mousewheelListener,
181+
this.props.useCapture,
182+
);
162183
scrollEl.addEventListener(
163184
'scroll',
164185
this.scrollListener,
@@ -175,6 +196,16 @@ var InfiniteScroll = (function(_Component) {
175196
}
176197
},
177198
},
199+
{
200+
key: 'mousewheelListener',
201+
value: function mousewheelListener(e) {
202+
// Prevents Chrome hangups
203+
// See: https://stackoverflow.com/questions/47524205/random-high-content-download-time-in-chrome/47684257#47684257
204+
if (e.deltaY === 1) {
205+
e.preventDefault();
206+
}
207+
},
208+
},
178209
{
179210
key: 'scrollListener',
180211
value: function scrollListener() {

src/InfiniteScroll.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,27 @@ export default class InfiniteScroll extends Component {
4848

4949
componentWillUnmount() {
5050
this.detachScrollListener();
51+
this.detachMousewheelListener();
5152
}
5253

5354
// Set a defaut loader for all your `InfiniteScroll` components
5455
setDefaultLoader(loader) {
5556
this.defaultLoader = loader;
5657
}
5758

59+
detachMousewheelListener() {
60+
let scrollEl = window;
61+
if (this.props.useWindow === false) {
62+
scrollEl = this.scrollComponent.parentNode;
63+
}
64+
65+
scrollEl.removeEventListener(
66+
'mousewheel',
67+
this.mousewheelListener,
68+
this.props.useCapture,
69+
);
70+
}
71+
5872
detachScrollListener() {
5973
let scrollEl = window;
6074
if (this.props.useWindow === false) {
@@ -83,6 +97,11 @@ export default class InfiniteScroll extends Component {
8397
scrollEl = this.scrollComponent.parentNode;
8498
}
8599

100+
scrollEl.addEventListener(
101+
'mousewheel',
102+
this.mousewheelListener,
103+
this.props.useCapture,
104+
);
86105
scrollEl.addEventListener(
87106
'scroll',
88107
this.scrollListener,
@@ -99,6 +118,14 @@ export default class InfiniteScroll extends Component {
99118
}
100119
}
101120

121+
mousewheelListener(e) {
122+
// Prevents Chrome hangups
123+
// See: https://stackoverflow.com/questions/47524205/random-high-content-download-time-in-chrome/47684257#47684257
124+
if (e.deltaY === 1) {
125+
e.preventDefault();
126+
}
127+
}
128+
102129
scrollListener() {
103130
const el = this.scrollComponent;
104131
const scrollEl = window;

0 commit comments

Comments
 (0)