jQuery实现滚动条动态加载

//滚动条加载底部自动加载
$(function(){
    //鼠标滚动事件
    $(window).scroll(function(){
        console.log("滚动条到顶部的垂直高度:" +  $(window).scrollTop() );
        console.log("页面的文档高度:" +  $(document).height() );
        console.log("浏览器的高度:" +  $(window).height() );
//下面这句主要是获取网页的总高度,主要是考虑兼容性所以把Ie支持的documentElement也写了,这个方法至少支持IE8
        var htmlHeight=document.body.scrollHeight||document.documentElement.scrollHeight;
        //clientHeight是网页在浏览器中的可视高度,
        var clientHeight=document.body.clientHeight||document.documentElement.clientHeight;
        //scrollTop是浏览器滚动条的top位置,
        var scrollTop=document.body.scrollTop||document.documentElement.scrollTop;
        //通过判断滚动条的top位置与可视网页之和与整个网页的高度是否相等来决定是否加载内容;
        if(scrollTop+clientHeight==htmlHeight){
             start+=length;
            findBookList(start,length);
            // 延时
             // setTimeout(function () {
             //
             // },1000)

        }
    })

猜你喜欢

转载自blog.csdn.net/qq_37279279/article/details/79803877