繁体   English   中英

当用户滚动到页面底部时无法检测

[英]Cannot Detect When User Scrolls to the Bottom of Page

我正在使用以下代码来检测用户何时滚动到页面底部:

$(window).on("scroll", function() {
    var scrollHeight = $(document).height();
    var scrollPosition = $(window).height() + $(window).scrollTop();
    if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
        // when scroll to bottom of the page
    }
});

但是,当我滚动到页面底部时,并没有告诉我,if语句变为真。 为什么会这样呢? 非常感谢。 我需要检测用户何时滚动到底部,是为了可以从服务器动态加载内容。 我认为这无关紧要,但是我在后端使用Flask,并且故障页面使用jinja-2渲染为模板。

_onScrollHandler(event){
if(event.target.scrollHeight - event.target.scrollTop === event.target.clientHeight){
console.log('Reacehd Bottom')
} 
}

在发生onscroll事件时调用此函数,并且从事件arg中可以获取scrollHeight,scrollTop和clientheight。 请尝试这个

暂无
暂无

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

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