码迷,mamicode.com
首页 > Web开发 > 详细

(swiper+dropload).js实现选项卡下拉加载分页

时间:2018-03-01 19:48:31      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:find   问题   ken   ack   .ajax   load   tar   gpo   trend   

依赖库:swiper.min.js+dropload.min.js

  

//dropload
var tabIndex = 0;
var tab1LoadEnd = false;
var tab2LoadEnd = false;
var counter = 0;
// 每页展示4个
var num = 10;
var pageStart = 0, pageEnd = 0;
var dropload = $(‘.swiper-slide‘).dropload({
scrollArea: window,
autoLoad: true,
loadDownFn: function (me) {
// 加载菜单一的数据
if (tabIndex == 0) {
$.ajax({
type: ‘GET‘,
data: {
token: token,
uid: uid,
type: 0,
pageSize: 10000
},
url: apiHost + ‘app/usigns/getinvitedetais‘,
dataType: ‘json‘,
success: function (data) {
var firstList = ‘‘;
counter++;
pageEnd = num * counter;
pageStart = pageEnd - num;
var firResult = data.data.data;
var firArrLen = firResult.length;
if (pageStart <= firArrLen) {
for (var i = pageStart; i < pageEnd; i++) {
firstList += ‘<li>‘
+ ‘<div class="detail-name fll">‘ + firResult[i].nickname + ‘</div>‘
+ ‘<div class="detail-money flr">‘
+ ‘<h3 class="money-top">‘ + firResult[i].lable + ‘</h3>‘
+ ‘<span class="time-buttom">‘ + timeFormat(firResult[i].create_at) + ‘</span>‘
+ ‘</div>‘
+ ‘</li>‘;
if ((i + 1) >= firArrLen) {
// 数据加载完
tab1LoadEnd = true;
// 锁定
me.lock();
// 无数据
me.noData();
break;
}
};
};
setTimeout(function () {
$(‘#successList‘).append(firstList);
// 每次数据插入,必须重置
me.resetload();
}, 500);
},
error: function (xhr, type) {
alert(‘啊哦~~网络出现了点问题!‘);
// 即使加载出错,也得重置
me.resetload();
}
});
} else if (tabIndex == 1) {
me.resetload();
}
}
});

//swiper
var swiper = new Swiper(‘.swiper-container‘, {
pagination: ‘.swiper-pagination‘,
paginationClickable: true,
slideActiveClass: ‘swiper-slide-active‘,
observeParents: true,
observer: true,
initialSlide: 0,//初始索引
paginationBulletRender: function (swiper, index, className) {
if (index == 0) {
return ‘<li class="‘ + className + ‘">成功邀请</li>‘;
} else if (index == 1) {
return ‘<li class="‘ + className + ‘">邀请奖励</li>‘;
}
},
onSlideChangeEnd: function (swiper) {
//重置
dropload.resetload();
tabIndex = swiper.activeIndex;
if (swiper.activeIndex == 0) {//成功邀请
// 如果数据没有加载完
if (!tab1LoadEnd) {
// 解锁
dropload.unlock();
dropload.noData(false);
} else {
// 锁定
dropload.lock(‘down‘);
dropload.noData();
}
} else if (swiper.activeIndex == 1) {//邀请奖励
if (!tab2LoadEnd) {
// 解锁
dropload.unlock();
dropload.noData(false);
} else {
// 锁定
dropload.lock(‘down‘);
dropload.noData();
};

//加载第二条数据
if ($("#inviteList").find("li").length <= 0) {//防止重复加载
$.ajax({
type: ‘GET‘,
data: {
token: token,
uid: uid,
type: 1,
pageSize: 10000
},
url: apiHost + ‘app/usigns/getinvitedetais‘,
dataType: ‘json‘,
success: function (data) {
var secondList = ‘‘;
var secResult = data.data.data;
var secArrLen = secResult.length;
for (var i = 0; i < secArrLen; i++) {
secondList += ‘<li>‘
+ ‘<div class="detail-name fll">‘ + secResult[i].nickname + ‘</div>‘
+ ‘<div class="type2">‘ + secResult[i].lable + ‘</div>‘
+ ‘<div class="detail-money flr">‘
+ ‘<h3 class="money-top">‘ + secResult[i].commission + ‘</h3>‘
+ ‘<span class="time-buttom">‘ + timeFormat(secResult[i].create_at) + ‘</span>‘
+ ‘</div>‘
+ ‘</li>‘
};
setTimeout(function () {
$(‘#inviteList‘).append(secondList);
// 每次数据插入,必须重置
dropload.resetload();
}, 500);
},
error: function (xhr, type) {
alert(‘啊哦~~网络出现了点问题!‘);
// 即使加载出错,也得重置
dropload.resetload();
}
});
}
};
}
});

(swiper+dropload).js实现选项卡下拉加载分页

标签:find   问题   ken   ack   .ajax   load   tar   gpo   trend   

原文地址:https://www.cnblogs.com/lpggo/p/8489572.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!