问答详情
源自:3-2 网页滚动到顶部或者底部

页面一滚动就显示“已经到达底端”

页面只要滚动就显示到底部了(谷歌浏览器)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>滚动到顶端或底端判断</title>
    <style>
        #showDiv{
            width: 200px;
            height: 200px;
            margin-top: 2400px;
            background-color: red;
        }
    </style>
</head>
<body>
<div id="showDiv"></div>
<script>
    function scrollBottomOrTop() {
        var clients=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;//可视区域
        var scrollTop=document.body.scrollTop;//滚动的距离
        var wholeHeight=document.body.scrollHeight;//整个高度
        if(clients+scrollTop>=wholeHeight){
            alert("已经到达底端")
        };
        if(scrollTop==0){
            alert("已经到达顶端")
        };
    }
    window.onscroll=scrollBottomOrTop;
</script>


提问者:精慕门4072777 2018-05-30 11:37

个回答

  • 精慕门4072777
    2018-05-30 11:45:37

    重新试了一下,把<!DOCTYPE html>里面的html去掉就好了,请问大家谁知道是什么原因吗?