当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 滚动条判断是否滑动到顶部底部

滚动条判断是否滑动到顶部底部

2018年09月19日  | 移动技术网IT编程  | 我要评论
    /**
     * [滚动条]
     */
    $(window).scroll(function() {

        var scrolltop = $(this).scrolltop(); // 滚动条距离顶部的高度
        console.log("滚动条距离顶部的高度-->" + scrolltop);

        var scrollheight = $(document).height(); // 当前页面的总高度
        console.log("当前页面的总高度-->" + scrollheight);

        var clientheight = $(this).height(); // 当前可视的页面高度
        console.log("当前可视的页面高度-->" + clientheight);

        if (scrolltop + clientheight >= scrollheight) { // 距离顶部高度+可视高度 >= 文档总高度 即代表滑动到底部         

            // code...
            alert('已经到底了!');

        } else if (scrolltop <= 0) {

            // code...
            alert('已经到顶了!');

        }

    });

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网