Skip to content

Commit

Permalink
fix(module:affix): fix FPS drops
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Oct 27, 2017
1 parent 4efd6f7 commit aaad2a3
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/components/affix/nz-affix.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import { NzScrollService } from "../core/scroll/nz-scroll.service";
})
export class NzAffixComponent implements OnInit, OnDestroy {

private didScroll = false;
private scrollTime: any = null;
private scroll$: Subscription = null;
private scrollWinInTarget$: Subscription = null;
private target: Element = null;
Expand Down Expand Up @@ -92,19 +94,22 @@ export class NzAffixComponent implements OnInit, OnDestroy {
}

private removeListen() {
if (this.scrollTime) clearTimeout(this.scrollTime);
if (this.scroll$) this.scroll$.unsubscribe();
if (this.scrollWinInTarget$) this.scrollWinInTarget$.unsubscribe();
}

private registerScrollEvent() {
this.removeListen();
this.reCalculate().process();
this.scroll$ = (RxChain.from(fromEvent(this.getTarget(), 'scroll')) as RxChain<any>)
.call(throttleTime, 50)
.call(distinctUntilChanged)
.subscribe(e => {
this.scrollTime = setInterval(() => {
if (this.didScroll) {
this.didScroll = false;
this.process();
});
}
}, 100);
this.scroll$ = (RxChain.from(fromEvent(this.getTarget(), 'scroll')) as RxChain<any>)
.subscribe(() => this.didScroll = true);

if (this.getTarget() !== window) {
// 当 window 滚动位发生变动时,需要重新计算滚动容器
Expand Down

0 comments on commit aaad2a3

Please sign in to comment.