乐趣区

原生js-判断移动端页面是否滚动到底部

document.addEventListener('touchmove', function() {
            let scrollTopH = document.body.scrollTop || document.documentElement.scrollTop;
            var clientHeight = document.documentElement.scrollTop === 0 ? document.body.clientHeight : document.documentElement.clientHeight;
            var scrollTop = document.documentElement.scrollTop === 0 ? document.body.scrollTop : document.documentElement.scrollTop;
            var scrollHeight = document.documentElement.scrollTop === 0 ? document.body.scrollHeight : document.documentElement.scrollHeight;
            if (scrollTop != 0 && clientHeight + scrollTop == scrollHeight) {console.log('‘到达底部’')
            }
        })
退出移动版