Skip to content

Instantly share code, notes, and snippets.

@wangwen1220
Created August 28, 2014 08:45
Show Gist options
  • Save wangwen1220/2e9825b8557550e38e17 to your computer and use it in GitHub Desktop.
Save wangwen1220/2e9825b8557550e38e17 to your computer and use it in GitHub Desktop.
js:判断滚动条已经滚动到底部
// 判断滚动条已经滚动到底部
if (Math.abs(document.body.clientHeight - document.documentElement.clientHeight) <= (document.documentElement.scrollTop || document.body.scrollTop)) {
alert("滚到底部");
}
@CracKerMe
Copy link

前提是 body 的滚动,如果是 某一个 dom 节点内的 滚动场景则不适用,建议完善。

@1uokun
Copy link

1uokun commented Sep 1, 2018

if(scroll_elem.scrollHeight>scroll_elem.clientHeight){
        scroll_elem.addEventListener('scroll',function(){
           //...
        })
    }else {
        window.addEventListener('scroll',function(){
            //...
        })
    }

我现在遇到的问题是电脑端模式可以检测到滚动到底部,进入手机端模式后scrollHight没有标准地改变导致不能满足条件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment