1. 程式人生 > >判斷頁面滑動到底部

判斷頁面滑動到底部

window.addEventListener('scroll', function(){
    const scrollHeight = document.body.scrollHeight || document.documentElement.scrollHeight;
    const clientHeight = document.body.clientHeight || document.documentElement.scrollHeight;
    const scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
    if(scrollTop >= scrollHeight - clientHeight){
        console.log('頁面滑動到底部')
    }
})