brand-list.page.js
3.27 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
var $ = require('yoho-jquery'),
Swiper = require('yoho-swiper2');
var categoryHeight = $('.tab-box').height(),
gender,
isBrand;
var $intercept = $('.no-intercept'),
$list = $('.brand-list-box'),
$listBox = $('.list-box');
function channels(key) {
return {
'men': 1,
'women': 2,
'lifestyle': 4
}[key];
}
function initialize() {
$('.banner-swiper').each(function() {
if (!$(this).parents('.content').hasClass('hide') && $(this).hasClass('swiper-container-horizontal') === false && $(this).find('li').length > 1) {
new Swiper(this, {
preloadImages: false,
lazyLoading: true,
lazyLoadingInPrevNext: true,
lazyLoadingOnTransitionStart: true,
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li'
});
}
});
}
function loadData(channel, isBrand) {
var preUrl;
if (isBrand) {
preUrl = '/guang/brandList';
} else {
preUrl = '/guang/category';
}
$.ajax({
method: 'get',
url: preUrl,
data: {
gender: channel
},
success: function(data) {
if (isBrand) {
$('.brand-content').html(data);
} else {
$('.category-content').html(data);
}
initialize();
}
});
}
$('.channel-tab').find('li').click(function() {
gender = $(this).find('span').text().replace(/[^A-Za-z]+/g, '').toLowerCase();
isBrand = $('.brand-tab').find('.brand').hasClass('active');
$(this).addClass('focus').siblings().removeClass('focus');
loadData(channels(gender), isBrand);
});
// 点击字母,页面滚动到相关区域
$intercept.click(function() {
var name = $(this).attr('href').split('#')[1],
targetTop = $list.find('[name=' + name + ']').offset().top - categoryHeight;
$('html,body').animate({
scrollTop: targetTop
}, 200);
return false;
});
$('.brand-tab').find('li').click(function() {
$(this).addClass('active').siblings().removeClass('active');
if ($(this).hasClass('brand')) {
$('.brand-content').removeClass('hide').siblings().addClass('hide');
$('.brand-cha').removeClass('hide').siblings().addClass('hide');
} else {
$('.category-content').removeClass('hide').siblings().addClass('hide');
$('.cate-cha').removeClass('hide').siblings().addClass('hide');
}
initialize();
});
if ($listBox.find('li').length <= 0) {
$listBox.hide();
}
$(function() {
$('.banner-swiper').each(function() {
if (!$(this).parents('.content').hasClass('hide') && $(this).hasClass('swiper-container-horizontal') === false && $(this).find('li').length > 1) {
new Swiper(this, {
preloadImages: false,
lazyLoading: true,
lazyLoadingInPrevNext: true,
lazyLoadingOnTransitionStart: true,
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li'
});
}
});
});