SGN SGN - 1 month ago 30
TypeScript Question

Tracking scroll not working with Internet Explorer 11

I have the following code:

this.currentScrollYSub = Observable.fromEvent(window, 'scroll')
.throttleTime(5)
.subscribe(e => {
this.scrollY = window.scrollY;
console.log(window.scrollY); // Result: undefined
});


Which works just fine on Chrome, but I noticed that on IE 10 and IE 11, it doesn't work.

How can i make this work on Internet Explorer 11?

EDIT

I also tried something like this:

@HostListener('window:scroll', ['$event'])
track(event) {
console.debug("Scroll Event ", document.body.scrollTop); // Result: "Scroll Event 0"
}

@HostListener('window:scroll', ['$event'])
track(event) {
console.debug("Scroll Event ", this.scrollY); // Result: "Scroll Event undefined"
}

Answer

https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY

Internet Explorer: No support

You can use something like:

return {
  x: window.pageXOffset || document.documentElement.scrollLeft,
  y: window.pageYOffset || document.documentElement.scrollTop
};

https://github.com/ReactTraining/react-router/issues/605

Comments