Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何处理角度上的上下滚动事件?_Javascript_Angular_Typescript_Rxjs - Fatal编程技术网

Javascript 如何处理角度上的上下滚动事件?

Javascript 如何处理角度上的上下滚动事件?,javascript,angular,typescript,rxjs,Javascript,Angular,Typescript,Rxjs,我有一个带有虚拟滚动项的div。我想在顶部滚动和底部滚动时获取事件 html: 但是,我认为这不是有效的解决办法 我知道,那个棱角分明的人有点古怪。我可以使用此调度程序处理上下滚动吗? 如果是,怎么做 谢谢大家! 您可以尝试以下两种方法 @ViewChild("scroll", { static: true }) scrollEle: ElementRef; fromEvent(scrollEle, "scroll") .pipe( tap()// do somethi

我有一个带有虚拟滚动项的div。我想在顶部滚动和底部滚动时获取事件

html:

但是,我认为这不是有效的解决办法

我知道,那个棱角分明的人有点古怪。我可以使用此调度程序处理上下滚动吗? 如果是,怎么做


谢谢大家!

您可以尝试以下两种方法

@ViewChild("scroll", { static: true }) scrollEle: ElementRef;

fromEvent(scrollEle, "scroll")
    .pipe(
        tap()// do something here
    )
    .subscribe();

 onScroll = (event): void => {
//handle your scroll here
//this is used to be able to remove the event listener
this.scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
console.log('scrolling ' + this.scrollTop);
if (this.scrollTop > 5) {
  this.showPreviosLog(this.previosLink);
  console.log('scroll top');
}
else {
  console.log('scroll bottom');
} 
@ViewChild("scroll", { static: true }) scrollEle: ElementRef;

fromEvent(scrollEle, "scroll")
    .pipe(
        tap()// do something here
    )
    .subscribe();
@HostListener("window:scroll", ["$event"])
    onScroll(event) {

    }