ps-tabpage.js
3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var $ = require('yoho.jquery'),
Swiper = require('yoho.iswiper'),
Mustache = require('yoho.mustache'),
FetchBrand = require('./fetchbrand'),
jgestures = require('yoho.jgestures');
var fetching = false,
pagecount = 10,
page = window.global_totalcount >= pagecount ? pagecount : window.global_totalcount,
loaded = {},
slideCache = [],
slideMap = {},
lastScrollY = window.pageYOffset,
scrollY = window.pageYOffset,
innerHeight,
topViewPort,
bottomViewPort;
/**
*获得模板
*/
var template, global_timer;
function showLoadPreview() {
document.querySelector('.loadmore').style.display = 'block';
}
function hideLoadPreview() {
document.querySelector('.loadmore').style.display = 'none';
}
/**
* 抓取数据
* @return {[type]} [description]
*/
function fetchBrands() {
if (fetching) {
return;
} else {
fetching = true;
}
var senddata = {
brandcat: global_brandcat,
start: page,
count: pagecount
};
var sendparams = {
data: senddata,
url: global_fetchdataurl
};
FetchBrand.FetchBrandDataInfo('brands', sendparams, function(data) {
var frag = Mustache.render(template, {
brandList: data.data.brandList
});
window.global_totalcount = data.data.total;
$('#' + global_showpannel).append(frag)
var swiper = $(frag).find('.swiper-container');
swiper = swiper.prevObject;
for (var i = 0; i < swiper.length; i++) {
(function(id) {
var swiperid = swiper[id].getAttribute('id');
new Swiper('.swiper-container' + swiperid, {
pagination: '.swiper-pagination' + swiperid,
lazyLoading: false,
lazyLoadingInPrevNext: false,
loop: false,
autoplay: false
});
})(i)
}
fetching = false;
hideLoadPreview();
page += pagecount;
});
}
/**
* 模拟滚动的函数
* @param {[type]} e [description]
* @param {[type]} force [description]
* @return {[type]} [description]
*/
function handleScroll(e, force) {
window.clearTimeout(global_timer);
if (page >= window.global_totalcount) {
return;
}
if (lastScrollY === window.scrollY) {
global_timer = window.setTimeout(handleScroll, 100);
return;
} else {
lastScrollY = window.scrollY;
}
scrollY = window.scrollY;
innerHeight = window.innerHeight; //窗口高度
topViewPort = scrollY - 6000;
bottomViewPort = scrollY + innerHeight + 6000;
if (window.scrollY + innerHeight >= document.body.offsetHeight) { //是否提前到底
showLoadPreview();
fetchBrands();
}
global_timer = window.setTimeout(handleScroll, 100);
}
/**抓取数据**/
function getBrand(catid) {
page = 0;
global_showpannel = 'showpannel' + catid;
global_brandcat = catid;
window.scrollTo(0, 0);
fetchBrands();
global_timer = window.setTimeout(handleScroll, 100);
}
/**
* 初始化
* @param {[type]} ) { window.setTimeout(handleScroll, 100); fetchBrands();} [description]
* @return {[type]} [description]
*/
exports.init = function() {
$.get('psTmplage', function(data) {
template = data;
Mustache.parse(template);
lastScrollY = window.scrollY;
global_timer = window.setTimeout(handleScroll, 500);
$('.navitemwrapper').bind('tapone', function() {
var nowActHeader = $(this),
preActHeader = $('.newfestivalbrandheader').data('actheadtag') || $('.hasunderline'),
tagId = nowActHeader.attr('tagid'),
nowActContent = $('#showpannel' + tagId),
preActContent = $('.newfestivalbrandheader').data('actcontenttag') || $('.newfestivalbrandwrapper .show');
preActHeader.removeClass('hasunderline');
nowActHeader.addClass('hasunderline');
$('.newfestivalbrandheader').data('actheadtag', nowActHeader);
preActContent.empty(); //清掉上个界面的数据
parenttop = nowActContent.offset().top; //重置高度
preActContent.removeClass('show').addClass('hide');
nowActContent.removeClass('hide').addClass('show');
$('.newfestivalbrandheader').data('actcontenttag', nowActContent);
var catid = tagId;
getBrand(catid);
});
});
}