Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't window.addEventListener('scroll', this.someScrollHandler, false) work on IE 10?

I'm currently building a React app with a scroll handler for loading more data in an infinite scroll component. I'm using window.addEventListener('scroll', this.someScrollHandler, false); (with throttling), which works on every browser except for IE — no event is handled.

In fact, testing in the IE console, the below code, then scrolling, results in no logging:

window.addEventListener('scroll', function() { console.log('testing') }, false);

What's going on with scroll events and IE?

like image 593
jcjcjcjc Avatar asked Jul 15 '15 19:07

jcjcjcjc


People also ask

How do I listen scrolling events in react?

To handle the onScroll event in React: Set the onScroll prop on an element or add an event listener on the window object. Provide an event handler function. Access relevant properties on the event or window objects.


2 Answers

My problem was that I had the body height 100%, that disabled the scroll event.

body {
   height: 100%; // <-- will disable window.addEventListener('scroll')
}
like image 148
Daantje Avatar answered Nov 15 '22 08:11

Daantje


After a lot of debugging, the problem was in the css. The app is responsive, so we had a base overflow-x: hidden style, then switching to overflow-x: initial after a breakpoint. Apparently IE doesn't like initial, so it was still picking up on the overflow hidden, thus preventing scroll events from firing. Switching to overflow-x: visible fixed the problem.

like image 27
jcjcjcjc Avatar answered Nov 15 '22 10:11

jcjcjcjc