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?
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.
My problem was that I had the body height 100%, that disabled the scroll event.
body {
height: 100%; // <-- will disable window.addEventListener('scroll')
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With