Jquery 判断滚动条到达顶部或底部

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>

    <script type="text/javascript" src="jquery-1.8.3.js"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            $(window).scroll(function() {
                //$(document).scrollTop() 获取垂直滚动的距离
                //$(document).scrollLeft() 这是获取水平滚动条的距离
                if ($(document).scrollTop() <= 0) {
                    alert("滚动条已经到达顶部为0");
                }

                if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
                    alert("滚动条已经到达底部为" + $(document).scrollTop());
                }
            });
        });
    
    
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 3000px; ">
    </div>
    </form>
</body>
</html>

赞一个,解决了我的一个问题。转自:http://blog.163.com/kunkun0921@126/blog/static/16920433220134891140441/

原文地址:https://www.cnblogs.com/snowhite/p/5363888.html