star.page.js
3.45 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
/**
* 星潮教室首页
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/5/31
*/
var $ = require('yoho-jquery'),
Swiper = require('yoho-swiper'),
lazyLoad = require('yoho-jquery-lazyload'),
ellipsis = require('yoho-mlellipsis');
var $starArticle = $('.star-article'),
$swiperView = $('.swiper-view'),
$viewImg = $('.view-img'),
imgs = [];
var avatarSwiper, avatarKey, mySwiper;
lazyLoad($('img.lazy'));
ellipsis.init();
// 限制标题字数
function txtLimit(dom) {
var $title = dom.find('.article-title'),
$cont = dom.find('p');
$title[0].mlellipsis(2);
$cont[0].mlellipsis(3);
}
// 明星动态文章图片相关操作
function articleImgAction(dom) {
var $articeImgs = dom.find('.artice-imgs'),
$li = $articeImgs.find('li'),
imgLen = $articeImgs.find('img').length,
addFlagDom = $li.eq(2);
var i;
imgs = [];
$li.each(function() {
imgs.push($(this).find('img').attr('src'));
});
$li.on('click', function() {
for (i = 0; i < imgLen; i++) {
$swiperView.find('ul').append('<li class="swiper-slide">' +
'<img class="swiper-lazy" data-src="' + imgs[i] + '">' +
'<div class="swiper-lazy-preloader"></div></li>');
}
setTimeout(function() {
mySwiper = new Swiper('.swiper-view', {
lazyLoading: true,
lazyLoadingInPrevNext: true,
slideElement: 'li'
});
}, 100);
$viewImg.show();
$('body').css({
overflow: 'hidden'
});
});
if (imgLen > 3 && addFlagDom.find('.img-size').length < 1) {
addFlagDom.append('<div class="img-size"><i class="pic-icon"></i>' + imgLen + '</div>');
}
}
if ($('.banner-swiper .swiper-slide').length > 1) {
new Swiper('.banner-swiper', {
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li',
pagination: '.banner-top .pagination-inner'
});
}
if ($('.avatar-swiper .swiper-slide').length > 1) {
avatarSwiper = new Swiper('.avatar-swiper', {
loop: true,
initialSlide: 3,
centeredSlides: true,
lazyLoading: true,
lazyLoadingInPrevNext: true,
slidesPerView: 'auto',
slidesOffsetBefore: '-' + $('.avatar-swiper').find('li').not('.swiper-slide-visible').width() / 2,
watchSlidesProgress: true,
watchSlidesVisibility: true
});
}
if ($('.star-avatar').length > 1) {
new Swiper('.article-avatar-swiper', {
initialSlide: 0,
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 5000
});
}
if ($('.star-info').find('li').length > 0) {
$starArticle.each(function(key, item) {
txtLimit($(item));
articleImgAction($(item));
});
}
$('body').addClass('star-index-bg');
// 明星头像点击居中显示或跳转
$('.avatar-swiper li').on('click', function() {
if ($(this).hasClass('swiper-slide-active')) {
location.href = $(this).find('img').data('url');
} else {
avatarKey = $(this).index();
avatarSwiper.slideTo(avatarKey, 1000, false);
}
});
$('.mask-bg').on('click', function() {
$viewImg.hide();
$viewImg.find('li').remove();
mySwiper.destroy(false);
$('body').css({
overflow: 'auto'
});
});