获取滚动条的距离

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

 

posted @ 2017-11-15 15:01  陌凌雪  阅读(927)  评论(0编辑  收藏  举报