![](/img/trans.png)
[英]How can I capture any scroll event from an element on the page using HostListener (Angular 7)?
[英]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.