检查用户是否已在 Angular 2 中滚动到底部 [英] Check if user has scrolled to the bottom in Angular 2

查看:20
本文介绍了检查用户是否已在 Angular 2 中滚动到底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查用户是否在没有 jQuery 的情况下在 Angular2 中滚动到页面底部的最佳做法是什么?我可以访问我的应用程序组件中的窗口吗?如果不是,我应该检查滚动到页脚组件的底部,我该怎么做?页脚组件上的指令?有人做到了吗?

What is the best practice to check if user has scrolled to the bottom of the page in Angular2 without jQuery? Do I have access to the window in my app component? If not should i check for scrolling to the bottom of the footer component, and how would I do that? A directive on the footer component? Has anyone accomplished this?

推荐答案

//你可以使用这个.

@HostListener("window:scroll", [])
onScroll(): void {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
        // you're at the bottom of the page
    }
}

这篇关于检查用户是否已在 Angular 2 中滚动到底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆