- const scrollObservable = fromEvent(window, 'scroll')
- .startWith(true)
- .map(() => ({ current: window.scrollY, maximumScroll: document.body.clientHeight - window.innerHeight }))
+ this.container = this.onItself
+ ? this.el.nativeElement
+ : document.documentElement
+
+ // Emit the last value
+ const throttleOptions = { leading: true, trailing: true }
+
+ const scrollableElement = this.onItself ? this.container : window
+ const scrollObservable = fromEvent(scrollableElement, 'scroll')
+ .pipe(
+ startWith(null as string), // FIXME: typings
+ throttleTime(200, undefined, throttleOptions),
+ map(() => this.getScrollInfo()),
+ distinctUntilChanged((o1, o2) => o1.current === o2.current),
+ share()
+ )