star.page.js
5.59 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
/**
* 星潮教室首页
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/5/31
*/
var $ = require('yoho-jquery'),
Swiper = require('yoho-swiper'),
loading = require('../plugin/loading'),
PullRefresh = require('../plugin/pull-refresh');
var $window = $(window),
stopLoading = false,
$mainContent = $('.main-content'),
$loadingTip = $('.loading-tip'),
u = navigator.userAgent,
isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
var avatarKey, bannerLen, res, avatarSwiper, getIndexHtml, bannerSwiper,
$avatarWrap, starIScroll;
var swiperNum = $('.avatar-wrap .swiper-slide').width() / 2,
topBanner = $('.banner-top');
if ($('.star-main').css('height') === '0px') {
$('.star-main').css('height', $window.height() - $('.head-tab').height());
}
if ($window.width() === 375 && isiOS) {
swiperNum = 32;
}
require('../common');
require('yoho-jquery-lazyload');
$window.on('mousewheel', false);
$('#yoho-header, .head-tab').on('touchmove', function() {
return false;
});
// 明星头像点击居中显示或跳转
function bindAvatar(dom) {
avatarKey = dom.index();
if (!dom.hasClass('swiper-slide-active')) {
return false;
}
}
function setIndexAction() {
// 明星头像 swiper 初始化
if (bannerLen > 1) {
avatarSwiper = new Swiper($avatarWrap.find('.avatar-swiper')[0], {
lazyLoading: true,
lazyLoadingInPrevNextAmount: 3,
// loop: true,
initialSlide: 2,
centeredSlides: true,
slidesPerView: 'auto',
loopedSlides: bannerLen,
spaceBetween: 10,
slidesOffsetBefore: -swiperNum,
watchSlidesProgress: true,
watchSlidesVisibility: true,
onInit: function() {
$avatarWrap.on('click', 'li', function() {
res = bindAvatar($(this));
return res;
});
}
});
}
// banner swiper 初始化
if ($('.banner-swiper').find('li').length > 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'
});
}
}
function initAction() {
$avatarWrap = $('.avatar-wrap');
bannerLen = $('.avatar-wrap').find('.swiper-slide').length;
$loadingTip.before($('.avatar-swiper').clone().addClass('avatar-clone').hide());
$('img.lazy').lazyload({
effect: 'fadeIn'
});
setIndexAction();
}
initAction();
// 首页数据请求
getIndexHtml = function() {
loading.showLoadingMask();
$.ajax({
url: '/guang/star/getIndexHtml',
dataType: 'html',
timeout: 5000
})
.done(function(data) {
if (data) {
$mainContent.html(data);
initAction();
}
})
.always(function() {
stopLoading = false;
loading.hideLoadingMask();
});
};
// 下拉刷新,上拉加载
starIScroll = new PullRefresh('.star-main', {
pullDown: function() {
if (!stopLoading) {
stopLoading = true;
getIndexHtml();
}
}
});
starIScroll.iScroll.on('scrollStart', function() {
bannerSwiper && bannerSwiper.stopAutoplay();
});
starIScroll.iScroll.on('scroll', function() {
$window.trigger('scroll');
});
starIScroll.iScroll.on('scrollEnd', function() {
if (-this.y <= topBanner.height()) {
bannerSwiper && bannerSwiper.startAutoplay();
}
});
window.setCookie('guangStarUid', window.queryString.uid);
// app埋点
var C_ID = window._ChannelVary[window.cookie('_Channel')];
// 点击星潮教室页面中的banner
$('.banner-top').find('li').on('click', function() {
if (!window._yas || !window._yas.sendAppLogs) {
return;
}
window._yas.sendAppLogs({
appop: 'YB_H5_STROLL_STAR_BANNER_C',
param: JSON.stringify({
C_ID: C_ID,
TAB_INDEX: 0,
TAB_NAME: '全部',
POS_ID: 2, // 轮播图
TO_URL: $(this).find('a')[0].href
})
}, true);
});
$('.swiper-slide-active').on('click', function() {
if (!window._yas || !window._yas.sendAppLogs) {
return;
}
window._yas.sendAppLogs({
appop: 'YB_H5_STROLL_STAR_BANNER_C',
param: JSON.stringify({
C_ID: C_ID,
TAB_INDEX: 0,
TAB_NAME: '全部',
POS_ID: 2, // 轮播图
TO_URL: $(this).find('a')[0].href
})
}, true);
});
// 点击星潮教室页面中的文章时
$('.star-info').on('click', function(e) {
if (!window._yas || !window._yas.sendAppLogs) {
return;
}
var $this = $(e.target),
$a = $this.closest('.star-article');
if ($a.length > 0) {
var $li = $this.parents('li');
window._yas.sendAppLogs({
appop: 'YB_H5_STROLL_STAR_FLR_C',
param: JSON.stringify({
C_ID: C_ID,
TAB_INDEX: 0,
TAB_NAME: '全部',
CONTENT_INDEX: $li.index() + 1,
CONTENT_ID: $li.data('id')
})
}, true);
}
});
setTimeout(function() {
if (!window._yas || !window._yas.sendAppLogs) {
return;
}
window._yas.sendAppLogs({
appop: 'YB_H5_STROLL_STAR_TAB_C',
param: JSON.stringify({
C_ID: C_ID,
TAB_INDEX: 0,
TAB_NAME: '全部'
})
}, true);
}, 500);