滚动条触底判断

$(function(){
    $(window).scroll(function(){
        let scrollHeight = $('body')[0].scrollHeight; // 滚动条需要滚动的高度(真实内容高度)
        let scrollTop = $(this).scrollTop(); //滚动条当前位置在真实内容的高度里占了多少(隐藏高度)
        let height = $(this).height(); //视窗高度

        if(height + scrollTop >= scrollHeight){
            console.log('scrollHeight: ' + scrollHeight);
            console.log('scrollTop: ' + scrollTop);
            console.log('height: ' + height);
            let $div = $('<div></div>')
            let html = '';
            for(let i=0;i<100;i++){
                let num = Math.random() * 1000;
                html += `<p>${num}</p>`;
            }
            $div.html(html);
            $('body').append($div)
        }
    })
})

猜你喜欢

转载自blog.csdn.net/qq_39910762/article/details/82178324