home.js
5.67 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
/**
* 首页
* @author: liangzhifeng<zhifeng.liang@yoho.cn>
* @date: 2015/10/12
*/
var $ = require('jquery'),
Swiper = require('yoho.iswiper'),
lazyLoad = require('yoho.lazyload'),
noticeScroll = require('../plugin/notice-scroll'),
$mobileWrap = $('.mobile-wrap'),
$overlay = $('.overlay'),
$sideNav = $('.side-nav'),
$subNav = $('.sub-nav'),
bannerSwiper,
recommendSwiper,
hotBrandsSwiper,
trendTopicSwiper,
goodsSwiper,
freshSwiper;
var start = 0,
swiperClass,
$logotrans = $('.home-header .logo'),
openSideNav = false,
isen = true;
var attachFastClick = require('./fastclick');
attachFastClick(document.body);
lazyLoad($('img.lazy'));
noticeScroll('.notice', $('.notice').data('time') * 1000);
$('.nav-btn').on('touchstart', function() {
$sideNav.css('pointer-events', 'none');
$mobileWrap.addClass('menu-open');
$overlay.show().css('opacity', 0.3);
$sideNav.addClass('on');
openSideNav = true;
setTimeout(function() {
$sideNav.css('pointer-events', 'auto');
}, 400);
return false;
});
function hideSideBar() {
openSideNav = false;
if ($mobileWrap.hasClass('menu-open')) {
$mobileWrap.removeClass('menu-open');
$overlay.hide();
$('.sub-nav').removeClass('show');
$sideNav.removeClass('on');
}
}
$overlay.on('touchstart', function() {
hideSideBar();
return false;
});
$sideNav.on('touchmove scroll', function() {
return false;
});
// 点击一级导航,弹出二级导航
$sideNav.on('touchend', 'li', function(e) {
if ($(this).find('.sub-nav').size() > 0) {
$('.sub-nav').removeClass('show');
$(this).find('.sub-nav').addClass('show');
$(this).find('.highlight').removeClass('highlight');
}
if (e.target.pathname === location.pathname) {
hideSideBar();
return false;
}
});
// 返回一级导航,收起二级导航
$subNav.each(function() {
$(this).find('li').eq(0).on('click', function() {
$('.sub-nav').removeClass('show');
return false;
});
}).on('touchstart', function(e) {
if (e.currentTarget !== e.target) {
$subNav.find('li').removeClass('current');
}
});
// 侧边栏点击背景色变化
function highlight($elem) {
$elem.find('li').on('touchstart', function() {
$elem.find('.highlight').removeClass('highlight');
$(this).addClass('highlight');
}).on('touchend touchcancel', function() {
$(this).removeClass('highlight');
});
}
highlight($sideNav);
highlight($subNav);
// 头部banner轮播
if ($('.banner-swiper').find('li').size() > 1) {
bannerSwiper = new Swiper('.banner-swiper', {
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li',
pagination: '.banner-top .pagination-inner'
});
}
// 热门品牌滑动
hotBrandsSwiper = new Swiper('.brands-swiper', {
grabCursor: true,
slidesPerView: 'auto',
wrapperClass: 'brands-list',
slideElement: 'li'
});
// 推荐搭配滑动
recommendSwiper = new Swiper('.recommend-swiper', {
grabCursor: true,
slidesPerView: 'auto',
wrapperClass: 'recommend-list',
slideElement: 'li'
});
// 潮品话题轮播
if ($('.trend-topic-swiper').find('li').size() > 1) {
trendTopicSwiper = new Swiper('.trend-topic-swiper', {
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li',
pagination: '.trend-topic-content .pagination-inner'
});
}
// 新人专享轮播
if ($('.fresh-list-swiper').find('li').size() > 1) {
freshSwiper = new Swiper('.fresh-list-swiper', {
lazyLoading: true,
lazyLoadingInPrevNext: true,
grabCursor: true,
slidesPerView: 'auto',
slideElement: 'li',
watchSlidesVisibility: true
});
}
// 潮流上装/经典裤装等轮播
$('.category-swiper').each(function(i, index) {
swiperClass = 'category-swiper' + i;
$(this).addClass(swiperClass);
if ($('.' + swiperClass).find('.swiper-slide').size() > 1) {
goodsSwiper = new Swiper('.' + swiperClass, {
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li',
pagination: '.' + swiperClass + ' .pagination-inner'
});
}
});
// logo动画
function tsAnimate() {
start = start + 10;
$logotrans.css({
transform: 'rotateX(' + start + 'deg)',
'-webkit-transform': 'rotateX(' + start + 'deg)',
'-moz-transform': 'rotateX(' + start + 'deg)'
});
if (start / 90 % 2 === 1) {
if (isen) {
$logotrans.addClass('animate');
isen = false;
} else {
$logotrans.removeClass('animate');
isen = true;
}
}
if (start / 90 % 2 === 0 && start % 360 !== 0) {
window.setTimeout(tsAnimate, 3000);
} else {
if (start % 360 === 0) {
window.setTimeout(tsAnimate, 60 * 1000);
} else {
window.requestAnimationFrame(tsAnimate);
}
}
}
setTimeout(tsAnimate, 3000);
$('.home-header .iconfont').on('touchstart', function() {
$(this).addClass('highlight');
}).on('touchend touchcancel', function() {
$(this).removeClass('highlight');
});
// 底部留出tab 的高度
window.reMarginFooter('.footer-tab');
// set cookie
exports.set = function(c) {
window.setCookie('_Channel', c, {
expires: 365,
domain: '.m.yohobuy.com'
});
};
require('./maybe-like')();