第一次成功第二次成功 无限滚动加载 - 丽人女性网 乐动app 官网,ldsports网页版登入,乐动在线入口

第一次成功第二次成功 无限滚动加载

时间:2019-02-11 10:12:05 来源:丽人女性网 责任编辑:yangjing
var time1;
var srcollOld = 0,srcollNow = 0,scrollFun = false;
$(window).scroll(function () {
//$(window).scrollTop()这个方法是当前滚动条滚动的距离
//$(window).height()获取当前窗体的高度
//$(document).height()获取当前文档的高度
var bot = 50; //bot是底部距离的高度
if ((bot + $(window).scrollTop() ) >= ($(document).height() - $(window).height())) {
srcollNow = $(window).scrollTop();
if(srcollNow >= srcollOld){
if(!scrollFun){
//第一次请求完成后才发第二次请求
scrollFun = true;
clearTimeout(time1);
time1=window.setTimeout(function(){
loadAjax()
},500);
}
}
srcollOld = srcollNow;
}
});
function loadAjax(){
$.ajax({
url: url,
type: type,
success:function (data) {
scrollFun = false;
if (data.success == true) {
}else{
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
scrollFun = false;
}
});
}

  --------------------------------------------------------------------------------------------------------------------------------------------------------

                var pageNum = 5;
       var listHeight = $(".house-list").height();
var scrollFun = false;
var time1;
//获取购买数据
function getBuyData(releaseType, pageSize) {
$.ajax({
url: apis + "wap/house/page/filter?releaseType=" + releaseType + "&pageSize=" + pageSize,
type: "GET",
dataType: "json",
success: function(data) {
scrollFun = false;
console.log(data);
if(data.code == "000000") {
var buyData = data.data
console.log(buyData)
var html = "";
for(var i of buyData) {
console.log(i)
html += `





  • ${"$"+countSum(i.price)}





    455sqft


    4bd


    4ba



    ${i.street}



  • `;
    }
    }
    },
    error: function(data) {
    scrollFun = false;
    }
    }).then(function() {
    //获取滚动条到顶部的垂直高度
    $(window).scroll(function() {
    var scrollHeight = ($(".house-list").children().length - 4) * $(".house-list li").height() - $(".search-box").height()
    console.log($(document).scrollTop() >= scrollHeight);
    if($(document).scrollTop() >= scrollHeight) {
    if(!scrollFun) {
    //第一次请求完成后才发第二次请求
    scrollFun = true;
    clearTimeout(time1);
    time1 = window.setTimeout(function() {
    console.log(6565665)
    pageNum += 5
    console.log(pageNum)
    getBuyData(2, pageNum);
    }, 500);
    }
    }
    });
    })
    }
                    getBuyData(2, pageNum);
    Copyright ? 丽人女性网 网站内容来自网络,如有侵权请联系我们,立即删除! 关于我们 联系我们 版权信息 赣ICP备17006263号-4