我有两个观测值Observable.of(0, animationFrame)Observable.fromEvent(window, 'scroll')。我想将它们组合在一起,以便仅在animationFrame的刻度上调用renderScrollBar(event)

  Observable.fromEvent(window, 'scroll')
      .map((event: any) => event.currentTarget)
      .subscribe((event) => {
        this._renderScrollBar(event);
      });
  let x = 0;
  Observable.of(0, animationFrame)
      .repeat()
      .takeUntil(Observable.timer(1000))
      .subscribe(() => console.log(x++));
}

最佳答案

如果要将节流滚动事件限制到requestAnimationFrame,则可以使用throttleTime(0, animationFrame)运算符代替Observable.of(0, animationFrame)



Observable.fromEvent(window, 'scroll')
    .throttleTime(0, animationFrame)

09-13 09:30