检查滚动是否在谷歌浏览器的 jquery 底部

Vic*_*ria 5 javascript django jquery google-chrome

我有 django 项目,但无法让 jquery 脚本在 google chrome 中运行。

检查滚动是否在底部的简单代码:

 <script language="JavaScript" type="text/JavaScript">
    window.onload = function () {

       $('#scrolling').on('scroll', chk_scroll);
    };

    function chk_scroll(e) {

        var elem = $(e.currentTarget);
        if (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight()) {
           alert("bottom")
        }
    }
</script>
Run Code Online (Sandbox Code Playgroud)

它适用于 Opera、Explorer、Firefox、Chrome(作为单个 html 文件,不是项目的一部分)、jsfiddle。

Ps jquery 正确加载,其他脚本正常工作。

ste*_*gro 0

请尝试以下操作:

$( window ).on( 'scroll', checkScroll );


function checkScroll()
{
    const documentScrollTop     = $( document ).scrollTop();
    const documentOuterHeight   = $( document ).outerHeight();
    const windowOuterHeight     = $( window ).outerHeight();

    if ( documentScrollTop >= documentOuterHeight - windowOuterHeight )
    {
        //bottom
    }
}
Run Code Online (Sandbox Code Playgroud)

除了窗口之外,您不需要使用任何元素来检查是否已触底