网页滚动到底部,拉取数据

网页滚动模式

//滚到到底部自动拉取数据
        //页面滚到底部异步加载下一页数据
        $(window).scroll(function () {
            //已经滚动到上面的页面高度
            var scrollTop = parseFloat($(this).scrollTop()),
                //页面高度
                scrollHeight = $(document).height(),
                //浏览器窗口高度
                windowHeight = parseFloat($(this).height()),
                totalHeight = scrollTop + windowHeight;

            //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
            if (scrollTop + windowHeight >= scrollHeight - 0.7) {

                var index = $('.swiper-slide-active').data("index");
                var id = $('.swiper-slide-active').attr("id");
                eval(''+id+'('+Number(index)+1+','+pageNumber+',"'+userid+'")');
            }
        });

可滚动的元素 ,滚动到底部,触发获取数据

//滚到到底部自动拉取数据
        //页面滚到底部异步加载下一页数据
        $(".swiper-slide").scroll(function () {
            //已经滚动到上面的页面高度
            var scrollTop = parseFloat($(this).scrollTop()),
                //滚动高度
                scrollHeight = this.scrollHeight,
                //窗口高度
                windowHeight = $(this).height(),
                totalHeight = scrollTop + windowHeight;
            //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
            if (scrollTop + windowHeight >= scrollHeight - 0.7) {
                console.log("===");
                var nextIndex = Number($('.swiper-slide-active').data("index"))+1;
                var id = $('.swiper-slide-active').attr("id");
                eval('' + id + '(' + nextIndex + ',' + pageNumber + ',"' + userid + '")');
            }
        });

  

原文地址:https://www.cnblogs.com/yanqin/p/7127644.html