brand-list.page.js
4.77 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
var $ = require('yoho-jquery'),
Swiper = require('yoho-swiper2');
var categoryHeight = $('.tab-box').height(),
gender;
var $intercept = $('.no-intercept'),
$list = $('.brand-list-box'),
$listBox = $('.list-box'),
$brandContent = $('.brand-content'),
$tabBox = $('.tab-box'),
$contentIndex = $('.content-index'),
$categoryNav = $('.category-nav'),
$channelTab = $('.channel-tab'),
$categoryContent = $('.category-content'),
$brandCha = $('.brand-cha');
require('../common');
require('./brand-cate/cate-all');
function channels(key) {
var channel = {
men: 1,
women: 2,
lifestyle: 4
};
return channel[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) {
$.ajax({
method: 'get',
url: '/guang/plusstar/brandList',
data: {
gender: channel
},
success: function(data) {
$brandContent.html(data);
initialize();
}
});
}
$brandCha.find('li').click(function() {
gender = $(this).find('span').text().replace(/[^A-Za-z]+/g, '').toLowerCase();
$(this).addClass('focus').siblings().removeClass('focus');
loadData(channels(gender));
});
// 点击字母,页面滚动到相关区域
$intercept.click(function() {
var name = $(this).attr('href').split('#')[1] === '0_9' ? '0~9' : $(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')) {
$brandContent.removeClass('hide').siblings().addClass('hide');
$channelTab.removeClass('hide');
$brandCha.removeClass('hide').siblings().addClass('hide');
} else {
$categoryContent.removeClass('hide').siblings().addClass('hide');
$('.channel-tab').addClass('hide');
}
initialize();
// 页面切换回到头部
$('html,body').animate({
scrollTop: 0
}, 100, function() {
if (!$brandContent.hasClass('hide')) {
$tabBox.removeClass('fastening');
$contentIndex.removeClass('distance');
} else {
$tabBox.removeClass('fastening');
$categoryNav.removeClass('loca');
$('.blk-cate-all .content').removeClass('living');
$contentIndex.removeClass('distance');
}
});
});
if ($listBox.find('li').length <= 0) {
$listBox.hide();
}
$(window).scroll(function() {
var totalHeight = $('#yoho-header').height() + $('.tab-box').height();
if (!$brandContent.hasClass('hide')) {
if ($(this).scrollTop() >= $('#yoho-header').height()) {
$tabBox.addClass('fastening');
$contentIndex.addClass('distance');
$('.list-box').css('top', $('.tab-box').height());
} else {
$tabBox.removeClass('fastening');
$contentIndex.removeClass('distance');
$('.list-box').css('top', totalHeight - $(this).scrollTop());
}
} else {
if ($(this).scrollTop() >= $('#yoho-header').height()) {
$tabBox.addClass('fastening');
$categoryNav.addClass('loca');
$('.blk-cate-all .content').addClass('living');
} else {
$tabBox.removeClass('fastening');
$categoryNav.removeClass('loca');
$('.blk-cate-all .content').removeClass('living');
}
}
});
$(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'
});
}
});
});