t.js
12.0 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
(function($) {
$.fn.jCarouselLite = function(o) {
o = $.extend({
btnPrev: null,
btnNext: null,
btnGo: null,
mouseWheel: false,
auto: null,
speed: 200,
easing: null,
vertical: false,
circular: true,
visible: 3,
start: 0,
scroll: 1,
beforeStart: null,
afterEnd: null
},
o || {});
return this.each(function() {
var b = false,
animCss = o.vertical ? "top": "left",
sizeCss = o.vertical ? "height": "width";
var c = $(this),
ul = $(" >ul", c),
tLi = $(">li", ul),
tl = tLi.size(),
v = o.visible;
if (o.circular) {
ul.prepend(tLi.slice(tl - v - 1 + 1).clone()).append(tLi.slice(0, v).clone());
o.start += v
}
var f = $(">li", ul),
itemLength = f.size(),
curr = o.start;
c.css("visibility", "visible");
f.css({
overflow: "hidden",
float: o.vertical ? "none": "left"
});
ul.css({
margin: "0",
padding: "0",
position: "relative",
"list-style-type": "none",
"z-index": "1"
});
c.css({
overflow: "hidden",
position: "relative",
"z-index": "2",
left: "0px"
});
var g = o.vertical ? height(f) : width(f);
var h = g * itemLength;
var j = g * v;
f.css({
width: f.width(),
height: f.height()
});
ul.css(sizeCss, h + "px").css(animCss, -(curr * g));
c.css(sizeCss, j + "px");
if (o.btnPrev) $(o.btnPrev).click(function() {
return go(curr - o.scroll)
});
if (o.btnNext) $(o.btnNext).click(function() {
return go(curr + o.scroll)
});
if (o.btnGo) $.each(o.btnGo,
function(i, a) {
$(a).click(function() {
return go(o.circular ? o.visible + (i - 1) * o.scroll: i - 1)
})
});
if (o.mouseWheel && c.mousewheel) c.mousewheel(function(e, d) {
return d > 0 ? go(curr - o.scroll) : go(curr + o.scroll)
});
if (o.auto) setInterval(function() {
go(curr + o.scroll)
},
o.auto + o.speed);
function vis() {
return f.slice(curr).slice(0, v)
};
function go(a) {
if (!b) {
if (o.beforeStart) o.beforeStart.call(this, vis());
if (o.circular) {
if (a <= o.start - v - 1) {
ul.css(animCss, -((itemLength - (v * 2)) * g) + "px");
curr = a == o.start - v - 1 ? itemLength - (v * 2) - 1 : itemLength - (v * 2) - o.scroll
} else if (a >= itemLength - v + 1) {
ul.css(animCss, -((v) * g) + "px");
curr = a == itemLength - v + 1 ? v + 1 : v + o.scroll
} else curr = a
} else {
if (a < 0 || a > itemLength - v) return;
else curr = a
}
b = true;
ul.animate(animCss == "left" ? {
left: -(curr * g)
}: {
top: -(curr * g)
},
o.speed, o.easing,
function() {
if (o.afterEnd) o.afterEnd.call(this, vis());
b = false
});
if (!o.circular) {
$(o.btnPrev + "," + o.btnNext).removeClass("disabled");
$((curr - o.scroll < 0 && o.btnPrev) || (curr + o.scroll > itemLength - v && o.btnNext) || []).addClass("disabled")
}
}
return false
}
})
};
function css(a, b) {
return parseInt($.css(a[0], b)) || 0
};
function width(a) {
try {
return a[0].offsetWidth + css(a, 'marginLeft') + css(a, 'marginRight')
} catch(ex) {
return 0
}
};
function height(a) {
return a[0].offsetHeight + css(a, 'marginTop') + css(a, 'marginBottom')
}
})(jQuery);
function overall(root){
var root = root || document;
var re = /j_([\w_]+)/;
var funcs = {};
$(".js",root).each(function(i) {
var m = re.exec(this.className);
if (m) {
var f = funcs[m[1]];
if (!f) {
f = eval('CF.' + m[1].replace(/\_/gi,'.'));
funcs[m[1]] = f;
}
f && f(this);
}
});
}
var CF = new Object();
CF.common = {
//tabs切换
tabs: function(obj) {
$('>ul', obj).tabs();
},
//下拉菜单
dropMenu: function(obj) {
$('li', obj).hover(function() {
$('ul', this).fadeIn();
}, function() {
$('ul', this).hide();
});
},
productSaleClick: function(obj) {
var next = $(obj).parent().next();
$(obj).click(function() {
next.show();
CF.common.productSale(next);
return false;
});
$('#product-sale-close').click(function() {
next.hide();
});
},
productSale: function(obj) {
$('dd:eq(0)>ul>li', obj).hover(function() {
$(this).addClass('current');
}, function() {
$(this).removeClass('current');
});
},
//插入圆角
corner: function(obj) {
if ($.browser.msie && $.browser.version == '6.0') {
var obj = $(obj);
var height = obj.height();
var outerHeight = obj.outerHeight();
if (outerHeight % 2 != 0) {
obj.height(height + 1);
}
}
$('<div class="cornerLT"></div><div class="cornerRT"></div><div class="cornerLB"></div><div class="cornerRB"></div>').appendTo(obj);
},
//用户面板显隐
userPannel: {
insertIframe: function() {
if ($.browser.msie && $.browser.version == '6.0') {
var sIframe = '<iframe width="100%" height="100%" frameborder="0"></iframe>';
$('#userPannel').append(sIframe);
$('#userPannel-pop .module-popBox').append('<iframe frameborder="0"></iframe>');
}
},
showPrompt: function(elem) {
var obj = $(elem);
obj.show();
$('a.close', obj).click(function() {
$(obj).hide();
if (elem == "#userPannel-prompt") SetIeCookie('userpannel', 'close');
if (elem == "#userPannel-userInfo")SetIeCookie('userInfo','close');
return false
});
},
click: function(obj) {
var obj = $(obj);
var href = obj.attr('href').toString().match(/#(.*)/)[1];
var popId = $('#' + href);
obj.click(function() {
popId.show()
return false;
});
$('a.close', popId).click(function() {
popId.hide();
return false
});
},
//mouseover
hover: function(obj) {
var obj = $(obj);
var href = obj.attr('href').toString().match(/#(.*)/)[1];
var popId = $('#' + href);
obj.hover(function() {
popId.show();
}, function() {
popId.hide();
});
},
//pop mouseover
popHover: function(obj) {
$('div[id][id!="userPannel-prompt"][id!="userPannel-userInfo"][id!="userPannel-userLogin"]', obj).hover(function() {
$(this).show();
},
function() {
$(this).hide();
});
}
},
//hover行变色(公用)
lineHoverColor: function(obj) {
$(obj).children().hover(function() {
$(this).addClass('current');
}, function() {
$(this).removeClass('current');
});
},
lineHoverCurrent: function(obj) {
$(obj).children().click(function() {
$(this).parent().find('.current').removeClass();
$(this).addClass('current');
});
}
}
//首页
CF.index = {
//促销产品跑马灯
carouseProduct: function(obj){
var obj = $(obj);
var prevChild = obj.prev();
var visible = 1;
var liNums = $('li', obj).length;
var pageNum = Math.ceil( liNums/visible );
var pageStr = '';
prevChild.append('<ul class="jcarouseLiteNav chance"></ul>');
var jcarouseLiteNav = $('>ul.jcarouseLiteNav', prevChild);
for(var i = 0; i < pageNum; i++){
pageStr += '';
}
jcarouseLiteNav.prepend('' + pageStr + ' <li class="next"><a id="change"><span class="right">换一批<img src="images/chance_03.jpg"/></span></li>');
$('>li .1', jcarouseLiteNav).parent().addClass('current');
if(liNums <=visible){
jcarouseLiteNav.hide();
}
obj.jCarouselLite({
btnNext: $('>li.next ', jcarouseLiteNav),
btnPrev: $('>li.prev a', jcarouseLiteNav),
visible: visible,
scroll: visible,
speed: 1000,
afterEnd: function(a){
$('>li.current', jcarouseLiteNav).removeClass('current');
var currLI = $(a[0]).attr("class").split('order')[1];
$('>li:eq(' + currLI + ')', jcarouseLiteNav).addClass('current');
},
btnGo: $('>li:not([class*=previous]):not([class*=next]) a', jcarouseLiteNav)
})
var width = obj.width();
obj.width( width - 3 );
},
//最新卖场和省心生活跑马灯
carouseOther: function(obj){
var obj = $(obj);
var prevChild = obj.prev();
var pageNum = 3;
var pageStr = '';
prevChild.append('<ul class="jcarouseLiteNav"></ul>');
var jcarouseLiteNav = $('>ul.jcarouseLiteNav', prevChild);
for(var i = 0; i < pageNum; i++){
pageStr += '<li><a class="' + (i + 1) + '"><span>' + (i + 1) + '</span></a></li>';
}
jcarouseLiteNav.prepend('<li class="prev"><a><span>previous</span></a></li>' + pageStr + ' <li class="next"><a><span>next</span></a></li>');
$('>li .1', jcarouseLiteNav).parent().addClass('current');
obj.jCarouselLite({
btnNext: $('>li.next ', jcarouseLiteNav),
btnPrev: $('>li.prev a', jcarouseLiteNav),
visible: 1,
scroll: 1,
speed: 1000,
afterEnd: function(a){
$('>li.current', jcarouseLiteNav).removeClass('current');
var currLI = $(a[0]).attr("class").split('order')[1];
$('>li:eq(' + currLI + ')', jcarouseLiteNav).addClass('current');
},
btnGo: $('>li:not([class*=previous]):not([class*=next]) a', jcarouseLiteNav)
})
}
}
CF.other = {
picChange: function(obj){
$(obj).before('<div id="project-pic-nav">').find('ul').cycle({
fx:'fade',
timeout: 3000,
next:obj,
pager:'#project-pic-nav',
pageEvent:null
})
}
}
function GetCookie(name)
{
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
if(arr != null) return unescape(arr[2]); return null;
}
//写cookies函数
function SetIeCookie(name,value)//两个参数,一个是cookie的名子,一个是值
{
document.cookie = name + "="+ escape (value) + ";path=/;";
}
function SetuserPannel()
{
var cookie = GetCookie('userpannel');
if(cookie != 'close')
{
CF.common.userPannel.showPrompt('#userPannel-prompt');
}
}
function SetuserUserInfoPannel() {
var cookie = GetCookie('userInfo');
if (cookie != 'close') {
CF.common.userPannel.showPrompt('#userPannel-userInfo');
}
}
$(function() {
overall();
SetuserPannel();
SetuserUserInfoPannel();
})