gpt4 book ai didi

javascript - 如何在 Angular 中获取 clientHeight?

转载 作者:行者123 更新时间:2023-11-30 11:09:22 26 4
gpt4 key购买 nike

我试图在滚动页面时获取客户端高度:

@HostListener('window:scroll', ['$event']) onScrollEvent($event) {
if ($event.scrollHeight - $event.scrollTop === $event.clientHeight) {
console.log('scrolled to the end');
}
});

我需要检测用户是否滚动到页面末尾

最佳答案

我认为你可以这样做(see this post for other solutionsand this article for this solution):

@HostListener("window:scroll") onWindowScroll() {
let scroll = window.pageYOffset ||
document.documentElement.scrollTop ||
document.body.scrollTop || 0;

const max = document.documentElement.scrollHeight -
document.documentElement.clientHeight;

if (scroll === max) {
alert('Bottom');
}
}

See the Stackblitz demo here

关于javascript - 如何在 Angular 中获取 clientHeight?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54368388/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com