懒加载 触底加载

141 阅读1分钟

懒加载 (jquery)

function j() {

            let wsH = document.documentElement.scrollTop;

            let wH = window.innerHeight

            $.each($('#recommendList li'), function (index, item) {

                let osT = item.offsetTop

                let osH = item.offsetHeight

                if (wsH + wH > osT + 10) {

                    item.children[0].children[0].src = item.children[0].children[0].dataset.lz

                }

            })

        }

触底加载

window.onscroll = function() {

            // 页面的总高度

            console.log(document.documentElement.scrollHeight);  

            // 已滚动高度

            console.log(document.documentElement.scrollTop + window.innerHeight);

            if (document.documentElement.scrollTop + window.innerHeight >= document.documentElement.scrollHeight - 200 && !loading) {

                console.log('到底了');

                loading = true;

                page++;

                getList();

            }

        }