上拉刷新

var pageNum = 1;
var isScroll = true;
var loading_hint = $('<div class="loading-hint">暂无更多数据...</div>');
$(window).scroll(function(e) {
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(this).height();
var positionValue = (scrollTop + windowHeight) - scrollHeight;
if (positionValue >= -100) {
//执行ajax,获取数据
if(isScroll){
isScroll = false;
pageNum++;
$.ajax({
url:'请求的后台接口',
type:'GET',
dataType:'JSON',
success:function (res) {
console.log(res);
console.log(pageNum);
if(pageNum > res.last_page){
              //如果是最后一页 提示
$('.vegetables').after(loading_hint.clone());
// $('.loading-hint').fadeIn();
}else{
isScroll = true;
for(var i = 0;i < res.data.length;i++){
                 //克隆一个标签 循环更新数据 然后添加到页面中
var list_clone = $('.vegetables .vegetables-min:first-child').clone();
list_clone.attr('href','/Mobile/Product/productDetail?product_id=' + res.data[i].id);
list_clone.find('.imgcorn img').attr('src',res.data[i].img);
list_clone.find('.imgcorn_font').text(res.data[i].name);
list_clone.find('.moneyandsales .moneyandsales_money').text('¥' + res.data[i].price);
list_clone.find('.moneyandsales .moneyandsales_sales').text('销量' + res.data[i].salesVolume);
$('.vegetables').append(list_clone);
}
              //如果还有数据 移除提示
$('.loading-hint').remove();
}
},
error:function () {
isScroll = true;
}
})
}
}
e.preventDefault();
});

//提示css
.loading-hint {
display: block;
padding: 15px;
text-align: center;
color: #999;
}

转载于:https://www.cnblogs.com/n-p-c/p/10616526.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值