Skip to main content
 首页 » 编程设计

javascript之检查 Google Chrome 中的 jquery 滚动是否位于底部

2026年09月08日2落叶无声

我有 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> 

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

P.s jquery 正确加载并且其他脚本可以工作。

请您参考如下方法:

尝试以下操作:

$( window ).on( 'scroll', checkScroll ); 
 
 
function checkScroll() 
{ 
    const documentScrollTop     = $( document ).scrollTop(); 
    const documentOuterHeight   = $( document ).outerHeight(); 
    const windowOuterHeight     = $( window ).outerHeight(); 
 
    if ( documentScrollTop >= documentOuterHeight - windowOuterHeight ) 
    { 
        //bottom 
    } 
} 

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