触底下拉

    $(window).scroll(function(){
var flag=true;
var scrollTop = $(this).scrollTop(); //滚动条距离顶部的高度
var scrollHeight = $(document).height(); //当前页面的总高度
var clientHeight = $(this).height(); //当前可视的页面高度
// console.log("top:"+scrollTop+",doc:"+scrollHeight+",client:"+clientHeight);
if(scrollTop + clientHeight+1 >= scrollHeight){ //距离顶部+当前高度 >=文档总高度 即代表滑动到底部
//滚动条到达底部

text = $(this).text();
shou = $("#shou").val();
wei = $("#wei").val();
page=parseInt(shou)+1>wei?wei:parseInt(shou)+1
if(flag){
flag=false;
console.log(flag);
$.ajax({
url: "/home/index/goodslistpage",
type: "post",
data: {
page: wei
},
success: function (data) {

var flag=true;
var str = ''
$.each(data,function (k,v) {

if(v.name!== undefined) {
var val=$("#a"+v.id).val();
console.log("#a"+v.id);
console.log(val);
if (val == undefined){
console.log(1);
str+="<div class='content-item'>"
str+="<input type='hidden' id='a"+ v.id+"' value='1'>"
str+= " <a href='#' onclick='showDetail(this)' id='"+v.id+"'>"
str+= " <img src='" + v.cover + "' class=\"slide-image\"/>"
str+= " </a>"
str+= " <div class='content-item-title'>"
str+= " <text style=\"color:#353535;\">"+v.name+"</text>"
str+= " <text style=\"font-size:20rpx; color:#a9a9a9;\">"+v.brand_name+"· "+v.c_sname+"</text>"
str+= " </div>"
str+= " </div>"
}else{
return false;
flag=false;
}

}


})
if(flag){
$('#wei').val(data.page);
$(".cover").append(str)
}

}
})

}
posted @ 2020-05-07 10:41  php毛宏历的博客  阅读(153)  评论(0编辑  收藏  举报