Skip to content

Commit

Permalink
fix(module:affix): fix FPS drops (#490)
Browse files Browse the repository at this point in the history
close #477
  • Loading branch information
cipchk authored and vthinkxie committed Nov 4, 2017
1 parent a7204e0 commit 50b2606
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 50b2606

Please sign in to comment.