I want to listen scroll event and handler them by two function for two scroll.
One need a throttleTime() to save resource and the other cannot use throttleTime() because it need trigger immediately and it doesn't cast too much.
Now I add two fromEvent to handle them but question is they will both be fired if scroll event is triggered.
fromEvent(this.vscroll.nativeElement, 'scroll').pipe(throttleTime(200)).subscribe((e) => {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
this.timer = setTimeout(() => {
this.updateShow();
}, 201);
} else {
this.timer = setTimeout(() => {
this.updateShow();
}, 201);
}
});
fromEvent(this.vscroll.nativeElement, 'scroll').subscribe((e) => {
(document.body.querySelector('#headerScroll') as HTMLElement).style.marginLeft = -this.vscroll.nativeElement.scrollLeft + 'px';
});
In my component those two function won't happen at the same time, so what should I do to make it only trigger one function and prevent from the other being executed?