这是我的.html文件
<table class="table" #scroller [class.fixed]="fixed">
<thead>
</thead>
</table>
像这样。我的要求是,我想滚动表并在某些滚动后修复表头。
我的.ts文件就是这个
@ViewChild('scroller') scroller: ElementRef
@HostListener("window:scroll", ['$event'])
onWindowScroll($event) {
debugger;
let num = this.document.body.scrollTop;
if ( num >50 ) {
this.fixed = true;
}else if (this.fixed && num < 5) {
this.fixed = false;
}
}
但是当我一直使用这个窗口滚动方法时,它会被激活。我希望它只在滚动表格时被激活。所以我把这个元素与Viewchild一起使用。问题出在这个代码上。
let num = this.document.body.scrollTop;
我正在拿整个文件正文,我只想要桌面滚动事件。我怎么能用elementref来做。请帮帮我。谢谢。