|
@@ -6,16 +6,19 @@ |
|
@@ -6,16 +6,19 @@ |
6
|
|
6
|
|
7
|
var $ = require('yoho-jquery'),
|
7
|
var $ = require('yoho-jquery'),
|
8
|
Swiper = require('yoho-swiper'),
|
8
|
Swiper = require('yoho-swiper'),
|
|
|
9
|
+ tip = require('../plugin/tip'),
|
9
|
lazyLoad = require('yoho-jquery-lazyload'),
|
10
|
lazyLoad = require('yoho-jquery-lazyload'),
|
10
|
- ellipsis = require('yoho-mlellipsis');
|
11
|
+ ellipsis = require('yoho-mlellipsis'),
|
|
|
12
|
+ loading = require('../plugin/loading'),
|
|
|
13
|
+ PullRefresh = require('../plugin/pull-refresh');
|
11
|
|
14
|
|
12
|
var $window = $(window),
|
15
|
var $window = $(window),
|
13
|
- $starMain = $('.star-main'),
|
|
|
14
|
- $bannerTop = $('.banner-top'),
|
|
|
15
|
- $starArticle = $('.star-article'),
|
|
|
16
|
- $avatarWrap = $('.avatar-wrap'),
|
|
|
17
|
- bannerLen = $avatarWrap.find('.swiper-slide').length,
|
|
|
18
|
- avatarTop = parseInt($starMain.find('.avatar').css('margin-top'), 10),
|
16
|
+ stopLoading = false,
|
|
|
17
|
+ $mainContent = $('.main-content'),
|
|
|
18
|
+ $headTab = $('.head-tab'),
|
|
|
19
|
+ headTabH = $headTab.height(),
|
|
|
20
|
+ scrollH = $(window).height() - headTabH,
|
|
|
21
|
+ $loadingTip = $('.loading-tip'),
|
19
|
u = navigator.userAgent,
|
22
|
u = navigator.userAgent,
|
20
|
isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
|
23
|
isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
|
21
|
|
24
|
|
|
@@ -29,19 +32,22 @@ var $window = $(window), |
|
@@ -29,19 +32,22 @@ var $window = $(window), |
29
|
var mySwiper;
|
32
|
var mySwiper;
|
30
|
*/
|
33
|
*/
|
31
|
|
34
|
|
32
|
-var res, avatarSwiper, avatarSwiperClone, $avatarClone;
|
35
|
+var avatarKey, bannerLen, res, avatarSwiper, avatarSwiperClone, getIndexHtml,
|
|
|
36
|
+ $avatarClone, $starArticle, $avatarWrap, starIScroll;
|
33
|
|
37
|
|
34
|
var swiperNum = $('.avatar-wrap .swiper-slide').width() / 2;
|
38
|
var swiperNum = $('.avatar-wrap .swiper-slide').width() / 2;
|
35
|
|
39
|
|
36
|
-require('../common');
|
|
|
37
|
-
|
|
|
38
|
if ($window.width() === 375 && isiOS) {
|
40
|
if ($window.width() === 375 && isiOS) {
|
39
|
swiperNum = 32;
|
41
|
swiperNum = 32;
|
40
|
}
|
42
|
}
|
41
|
|
43
|
|
|
|
44
|
+require('../common');
|
|
|
45
|
+
|
42
|
lazyLoad($('img.lazy'));
|
46
|
lazyLoad($('img.lazy'));
|
43
|
ellipsis.init();
|
47
|
ellipsis.init();
|
44
|
|
48
|
|
|
|
49
|
+$window.on('mousewheel', false);
|
|
|
50
|
+
|
45
|
// 限制标题字数
|
51
|
// 限制标题字数
|
46
|
function txtLimit(dom, item1, item2) {
|
52
|
function txtLimit(dom, item1, item2) {
|
47
|
var $title = dom.find(item1),
|
53
|
var $title = dom.find(item1),
|
|
@@ -73,7 +79,7 @@ function setAvatar($userAvatar) { |
|
@@ -73,7 +79,7 @@ function setAvatar($userAvatar) { |
73
|
|
79
|
|
74
|
// 明星头像点击居中显示或跳转
|
80
|
// 明星头像点击居中显示或跳转
|
75
|
function bindAvatar(dom) {
|
81
|
function bindAvatar(dom) {
|
76
|
- var avatarKey = dom.index();
|
82
|
+ avatarKey = dom.index();
|
77
|
|
83
|
|
78
|
if (!dom.hasClass('swiper-slide-active')) {
|
84
|
if (!dom.hasClass('swiper-slide-active')) {
|
79
|
if (avatarKey >= (2 * bannerLen + 1)) {
|
85
|
if (avatarKey >= (2 * bannerLen + 1)) {
|
|
@@ -91,48 +97,7 @@ function bindAvatar(dom) { |
|
@@ -91,48 +97,7 @@ function bindAvatar(dom) { |
91
|
}
|
97
|
}
|
92
|
}
|
98
|
}
|
93
|
|
99
|
|
94
|
-// 悬浮明星头像
|
|
|
95
|
-function cloneAvatarInit() {
|
|
|
96
|
- if ($window.scrollTop() >= $bannerTop.height() + avatarTop) {
|
|
|
97
|
- $avatarClone.show();
|
|
|
98
|
-
|
|
|
99
|
- if (!avatarSwiperClone) {
|
|
|
100
|
- avatarSwiperClone = new Swiper('.avatar-0', {
|
|
|
101
|
- loop: true,
|
|
|
102
|
- initialSlide: $('.avatar-1').find('.swiper-slide-active').index() % bannerLen,
|
|
|
103
|
- centeredSlides: true,
|
|
|
104
|
- slidesPerView: 'auto',
|
|
|
105
|
- loopedSlides: bannerLen,
|
|
|
106
|
- spaceBetween: 10,
|
|
|
107
|
- slidesOffsetBefore: -swiperNum,
|
|
|
108
|
- watchSlidesProgress: true,
|
|
|
109
|
- watchSlidesVisibility: true,
|
|
|
110
|
- onInit: function() {
|
|
|
111
|
- $('.avatar-0 li').on('click', function() {
|
|
|
112
|
- res = bindAvatar($(this));
|
|
|
113
|
- return res;
|
|
|
114
|
- });
|
|
|
115
|
- }
|
|
|
116
|
- });
|
|
|
117
|
-
|
|
|
118
|
- avatarSwiperClone.params.control = avatarSwiper;
|
|
|
119
|
- avatarSwiper.params.control = avatarSwiperClone;
|
|
|
120
|
- }
|
|
|
121
|
- } else {
|
|
|
122
|
- $avatarClone.hide();
|
|
|
123
|
- }
|
|
|
124
|
-}
|
|
|
125
|
-
|
|
|
126
|
-// 初始化首页各种效果
|
|
|
127
|
-function initAction() {
|
|
|
128
|
- $starMain.before($('.avatar-swiper').clone().addClass('avatar-clone').hide());
|
|
|
129
|
- $avatarClone = $('.avatar-clone');
|
|
|
130
|
-
|
|
|
131
|
- // 限制标题字数
|
|
|
132
|
- $('.cont-area').each(function() {
|
|
|
133
|
- txtLimit($(this), '.title', '.cont-txt');
|
|
|
134
|
- });
|
|
|
135
|
-
|
100
|
+function setIndexAction() {
|
136
|
$('.avatar').each(function(key, item) {
|
101
|
$('.avatar').each(function(key, item) {
|
137
|
$(item).addClass('avatar-' + key);
|
102
|
$(item).addClass('avatar-' + key);
|
138
|
});
|
103
|
});
|
|
@@ -198,14 +163,123 @@ function initAction() { |
|
@@ -198,14 +163,123 @@ function initAction() { |
198
|
$('#yoho-header, .head-tab').on('touchmove', function() {
|
163
|
$('#yoho-header, .head-tab').on('touchmove', function() {
|
199
|
return false;
|
164
|
return false;
|
200
|
});
|
165
|
});
|
|
|
166
|
+}
|
|
|
167
|
+
|
|
|
168
|
+function initAction() {
|
|
|
169
|
+ $starArticle = $('.star-article');
|
|
|
170
|
+ $avatarWrap = $('.avatar-wrap');
|
|
|
171
|
+ bannerLen = $('.avatar-wrap').find('.swiper-slide').length;
|
|
|
172
|
+
|
|
|
173
|
+ if ($avatarClone) {
|
|
|
174
|
+ $avatarClone.remove();
|
|
|
175
|
+ }
|
|
|
176
|
+
|
|
|
177
|
+ $loadingTip.before($('.avatar-swiper').clone().addClass('avatar-clone').hide());
|
201
|
|
178
|
|
202
|
- cloneAvatarInit();
|
179
|
+ $avatarClone = $('.avatar-clone');
|
|
|
180
|
+
|
|
|
181
|
+ // 限制标题字数
|
|
|
182
|
+ $('.cont-area').each(function() {
|
|
|
183
|
+ txtLimit($(this), '.title', '.cont-txt');
|
|
|
184
|
+ });
|
|
|
185
|
+
|
|
|
186
|
+ lazyLoad($('img.lazy'));
|
|
|
187
|
+
|
|
|
188
|
+ setIndexAction();
|
203
|
}
|
189
|
}
|
204
|
|
190
|
|
|
|
191
|
+
|
|
|
192
|
+// 首页数据请求
|
|
|
193
|
+getIndexHtml = function() {
|
|
|
194
|
+ loading.showLoadingMask();
|
|
|
195
|
+ $.ajax({
|
|
|
196
|
+ url: '/guang/star/getIndexHtml',
|
|
|
197
|
+ dataType: 'html',
|
|
|
198
|
+ success: function(data) {
|
|
|
199
|
+ stopLoading = false;
|
|
|
200
|
+
|
|
|
201
|
+ if (data) {
|
|
|
202
|
+ if (avatarSwiperClone) {
|
|
|
203
|
+ avatarSwiperClone.destroy(true, true);
|
|
|
204
|
+ avatarSwiperClone = '';
|
|
|
205
|
+ }
|
|
|
206
|
+
|
|
|
207
|
+ $mainContent.html(data);
|
|
|
208
|
+
|
|
|
209
|
+ initAction();
|
|
|
210
|
+ }
|
|
|
211
|
+
|
|
|
212
|
+ loading.hideLoadingMask();
|
|
|
213
|
+ },
|
|
|
214
|
+ error: function() {
|
|
|
215
|
+ tip.show('网络断开连接了~');
|
|
|
216
|
+ }
|
|
|
217
|
+ });
|
|
|
218
|
+};
|
|
|
219
|
+
|
205
|
initAction();
|
220
|
initAction();
|
206
|
|
221
|
|
207
|
-$window.scroll(function() {
|
|
|
208
|
- cloneAvatarInit();
|
222
|
+// 下拉刷新,上拉加载
|
|
|
223
|
+starIScroll = new PullRefresh('.star-main', {
|
|
|
224
|
+ height: scrollH,
|
|
|
225
|
+ pullDown: function() {
|
|
|
226
|
+ if (!stopLoading) {
|
|
|
227
|
+ stopLoading = true;
|
|
|
228
|
+ getIndexHtml();
|
|
|
229
|
+ }
|
|
|
230
|
+ }
|
|
|
231
|
+});
|
|
|
232
|
+
|
|
|
233
|
+starIScroll.iScroll.on('scrollStart', function() {
|
|
|
234
|
+ // 下拉
|
|
|
235
|
+ if (this.directionY === -1) {
|
|
|
236
|
+ $loadingTip.slideDown();
|
|
|
237
|
+ }
|
|
|
238
|
+});
|
|
|
239
|
+
|
|
|
240
|
+starIScroll.iScroll.on('scroll', function() {
|
|
|
241
|
+ if (this.directionY !== -1) {
|
|
|
242
|
+ starIScroll.iScroll.refresh();
|
|
|
243
|
+ }
|
|
|
244
|
+
|
|
|
245
|
+ if ($avatarWrap.offset().top <= headTabH) {
|
|
|
246
|
+ $avatarClone.show();
|
|
|
247
|
+
|
|
|
248
|
+ if (!avatarSwiperClone) {
|
|
|
249
|
+ avatarSwiperClone = new Swiper('.avatar-0', {
|
|
|
250
|
+ loop: true,
|
|
|
251
|
+ initialSlide: $('.avatar-1').find('.swiper-slide-active').index() % bannerLen,
|
|
|
252
|
+ centeredSlides: true,
|
|
|
253
|
+ slidesPerView: 'auto',
|
|
|
254
|
+ loopedSlides: bannerLen,
|
|
|
255
|
+ spaceBetween: 10,
|
|
|
256
|
+ slidesOffsetBefore: -swiperNum,
|
|
|
257
|
+ watchSlidesProgress: true,
|
|
|
258
|
+ watchSlidesVisibility: true,
|
|
|
259
|
+ onInit: function() {
|
|
|
260
|
+ $('.avatar-0 li').on('click', function() {
|
|
|
261
|
+ res = bindAvatar($(this));
|
|
|
262
|
+ return res;
|
|
|
263
|
+ });
|
|
|
264
|
+ }
|
|
|
265
|
+ });
|
|
|
266
|
+
|
|
|
267
|
+ avatarSwiperClone.params.control = avatarSwiper;
|
|
|
268
|
+ avatarSwiper.params.control = avatarSwiperClone;
|
|
|
269
|
+ }
|
|
|
270
|
+ }
|
|
|
271
|
+
|
|
|
272
|
+ if ($avatarWrap.offset().top > $('.avatar-1')[0].scrollHeight) {
|
|
|
273
|
+ $avatarClone.hide();
|
|
|
274
|
+ }
|
|
|
275
|
+});
|
|
|
276
|
+
|
|
|
277
|
+starIScroll.iScroll.on('scrollEnd', function() {
|
|
|
278
|
+ $loadingTip.slideUp();
|
|
|
279
|
+});
|
|
|
280
|
+
|
|
|
281
|
+$('img').on('load', function() {
|
|
|
282
|
+ starIScroll && starIScroll.iScroll.refresh();
|
209
|
});
|
283
|
});
|
210
|
|
284
|
|
211
|
window.setCookie('guangStarUid', window.queryString.uid);
|
285
|
window.setCookie('guangStarUid', window.queryString.uid);
|