繁体   English   中英

使用HostListener Angular +2在页面底部时如何获得警报

[英]How to get alert when you are at bottom of page using HostListener Angular +2

我正在使用此HostListener:

@HostListener("window:scroll", [])
    onWindowScroll() {
      const offset = this.window.pageYOffset || this.document.documentElement.scrollTop || this.document.body.scrollTop || 0;
      //How can I display an alert when I'm at bottom of page
    }

我用console.log(this.window.document.body.offsetHeight); 获取高度,以及当我使用console.log(this.window.pageYOffset); 并滚动到页面末尾,该数字不匹配。

干得好

onWindowScroll() {
  const offset = this.window.pageYOffset || this.document.documentElement.scrollTop || this.document.body.scrollTop || 0;
   if ((this.window.innerHeight + this.document.documentElement.scrollTop) >= this.document.body.offsetHeight) {
        alert("Rock bottom");
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM