在angular2中使用requestAnimationFrame

Sar*_*nan 4 angular

我想在angular2中实现无限滚动

  1. 自动删除视口外的DOM.
  2. 使用requestAnimationFrame代替onscroll.

我注意到上面是使用Mithriljs实现的,可以在下面的链接中找到.我对如何使用requestAnimationFrame并在angular2中构建一个名为ScrollListener的类感到困惑.请指教?

https://github.com/flarum/core/blob/master/js/lib/utils/ScrollListener.js

https://github.com/flarum/core/blob/master/js/forum/src/components/PostStream.js

PS:抱歉我的英文.我不是母语为英语的人.

Gün*_*uer 6

不确定您需要什么信息

是一个例子

class RafQueue {
  currentFrameId: number;
  constructor(public callback: Function, public frames: number) { this._raf(); }
  private _raf() {
    this.currentFrameId = DOM.requestAnimationFrame(timestamp => this._nextFrame(timestamp));
  }
  private _nextFrame(timestamp: number) {
    this.frames--;
    if (this.frames > 0) {
      this._raf();
    } else {
      this.callback(timestamp);
    }
  }
  cancel() {
    DOM.cancelAnimationFrame(this.currentFrameId);
    this.currentFrameId = null;
  }
}
Run Code Online (Sandbox Code Playgroud)

但我最近遇到了https://github.com/angular/angular/issues/6904(未检查,因为它再次正常工作)