outlets.page.js
4.23 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* 首页
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/05/31
*/
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload');
var $limitList = $('.limit-main .good-list'),
$limitBrand = $('.limit-main .brand-list'),
$fixNav = $('.sort-layer .full-line'),
$navPar,
homePage = $('.outlets-page').data('page');
var limitTime = [];
require('../common');
require('../plugins/slider');
require('./outlets/special');
function convertTime(time) {
var anHour = 3600000,
aMinute = 60000,
aSecond = 1000,
showTime = '',
d = 0,
h = 0,
m = 0,
s = 0;
if (time > 1000) {
d = Math.floor(time / anHour / 24);
h = Math.floor(time / anHour % 24);
m = Math.floor(time / aMinute % 60);
s = Math.floor(time / aSecond % 60);
showTime += d > 0 ? d + '天' : '';
showTime += h > 0 ? h + '时' : '';
showTime += m > 0 ? m + '分' : '';
showTime += s > 0 ? s + '秒' : '';
}
return showTime;
}
function setPageTime() {
var i, text, showTime, $par;
for (i = 0; i < limitTime.length; i++) {
if (limitTime[i].time < 0) {
return;
}
limitTime[i].time -= 1000;
showTime = convertTime(limitTime[i].time);
if (showTime) {
text = showTime;
if (limitTime[i].pre) {
text = limitTime[i].pre + ' ' + text;
}
} else {
$par = limitTime[i].dom.closest('.item-info').parent();
$par.find('a').attr('href', 'javascript:;');
text = '活动已结束';
}
limitTime[i].dom.text(text);
}
}
function limitPageSwitch(dom, num) {
dom.animate({
'margin-left': (-num * 10) + '0%'
}, 'fast').data({
page: num
});
}
// 上线预告&潮品推荐 公共处理方法
function formatExtraList(items, num) {
var html = '',
list = [],
i = 0;
if (!items.length) {
return;
}
items.each(function() {
if ((i % num) === 0) {
list.push('');
}
list[list.length - 1] += items[i].outerHTML;
i++;
});
if (list.length > 3) {
list.length = 3;
}
for (i = 0; i < list.length; i++) {
html += '<div class="list-page">' + list[i] + '</div>';
}
return {
length: list.length,
html: html
};
}
function extraInfo() {
var good = formatExtraList($limitList.find('.good-item'), 5),
brand = formatExtraList($limitBrand.find('.brand-item'), 9);
if (good && good.length > 1) {
$limitList.html(good.html).data({max: good.length});
$limitList.siblings('.page-btns').show();
}
if (brand && brand.length > 1) {
$limitBrand.html(brand.html).data({max: brand.length});
$limitBrand.siblings('.page-btns').show();
}
}
if ($fixNav.length) {
$navPar = $fixNav.parent();
$(window).scroll(function() {
var navTop = $navPar.position().top;
if ($(this).scrollTop() >= navTop) {
$fixNav.addClass('fixed');
} else {
$fixNav.removeClass('fixed');
}
});
}
// 倒计时
$('.time').each(function() {
var data = $(this).data();
if (data.limit) {
limitTime.push({
dom: $(this),
time: data.limit,
pre: data.pre ? data.pre : ''
});
}
});
$('.page-btns > label').click(function() {
var nowTime = new Date().getTime(),
$dom, data, max, page;
if ($(this).closest('.good-page-btns').length) {
$dom = $limitList;
} else {
$dom = $limitBrand;
}
data = $dom.data();
max = data.max ? data.max : 1;
page = data.page ? data.page : 0;
if (data.time && nowTime - data.time < 500) {
return;
}
$dom.data({
time: nowTime
});
if ($(this).hasClass('pre-page-btn')) {
page += max - 1;
} else {
page += 1;
}
page = page % max;
limitPageSwitch($dom, page);
});
setInterval(setPageTime, 1000);
if (homePage) {
$('.slide-container').slider({
orient: false
});
} else {
$('.slide-container').slider({
orient: true
});
}
extraInfo();
lazyLoad($('img.lazy'));