Authored by 王水玲

星潮教室首页明星头像效果

... ... @@ -12,7 +12,13 @@
<ul class="clearfix swiper-wrapper">
{{# starAvatar}}
<li class="swiper-slide">
<img class="rank-avatar" data-url="{{url}}" src="{{image cover 180 180}}">
<span class="rank-avatar" data-url="{{url}}" data-avatar="{{image cover 180 180}}"></span>
</li>
<li class="swiper-slide">
<span class="rank-avatar" data-url="{{url}}" data-avatar="{{image cover 180 180}}"></span>
</li>
<li class="swiper-slide">
<span class="rank-avatar" data-url="{{url}}" data-avatar="{{image cover 180 180}}"></span>
</li>
{{/ starAvatar}}
</ul>
... ... @@ -67,6 +73,52 @@
</div>
</div>
</li>
<li data-id="{{id}}">
<div class="star-avatar">
{{#if isSwiper}}
<div class="article-avatar-swiper">
<ul class="clearfix swiper-wrapper">
{{#each tags}}
<li class="swiper-slide">
<a href="{{avatarUrl}}">
<div data-avatar="{{image cover 100 100}}" class="rank-avatar" ></div>
<p class="name">{{tagName}}</p>
</a>
</li>
{{/each}}
</ul>
</div>
{{else}}
{{# tags}}
<a href="{{avatarUrl}}">
<div data-avatar="{{image cover 100 100}}" class="rank-avatar" ></div>
<p class="name">{{tagName}}</p>
</a>
{{/ tags}}
{{/if}}
</div>
<div class="star-article">
<i class="article-arrow"></i>
<a href="{{url}}"><h2 class="article-title">{{title}}</h2></a>
<div class="artice-cont">
<a href="{{url}}"><p>{{articeTxt}}</p></a>
<div class="artice-imgs-area">
<img src="{{image src 266 266}}" />
{{!-- <ul class="artice-imgs">
{{#each articeImg}}
<li><img src="{{image . 640 640}}" /></li>
{{/each}}
</ul> --}}
</div>
</div>
<div class="artice-o">
<span class="time"><i class="iconfont time-ico">&#xe603;</i>{{publishTime}}</span>
<span class="see"><i class="iconfont see-ico">&#xe602;</i>{{viewsNum}}</span>
</div>
</div>
</li>
{{/each}}
</ul>
</div>
... ...
<div class="star-page yoho-page">
{{> star/head-tab}}
<div class="swiper-num"></div>
<div class="star-main"></div>
</div>
... ...
... ... @@ -16,7 +16,8 @@ var $window = $(window),
$starArticle = $('.star-article'),
$headTab = $('.head-tab'),
stopLoading = false,
avatarSwiper = [],
avatarSwiper,
avatarSwiperClone,
getIndexHtml;
/*
... ... @@ -70,12 +71,19 @@ function setIndexAction() {
var $loadingTip = $('.loading-tip');
var $avatarWrap = $('.avatar-wrap');
var move;
// 下拉刷新,上拉加载
starIScroll = new PullRefresh('.star-wrap', {
height: $(window).height() - commonHeaderTop,
pullDown: function() {
if (!stopLoading) {
stopLoading = true;
if (avatarSwiperClone) {
avatarSwiperClone.destroy(true, true);
avatarSwiperClone = '';
}
getIndexHtml();
}
}
... ... @@ -91,11 +99,27 @@ function setIndexAction() {
starIScroll.iScroll.on('scroll', function() {
if (commonHeaderTop > $avatarWrap.offset().top) {
// $('.avatar-clone').css('top', $('.head-tab').outerHeight());
$('.avatar-clone').show();
starIScroll[0].update();
starIScroll[1].update();
} else {
if (!avatarSwiperClone) {
avatarSwiperClone = new Swiper('.avatar-0', {
loop: true,
initialSlide: $('.avatar-1').find('.swiper-slide-active').index(),
centeredSlides: true,
slidesPerView: 'auto',
loopedSlides: bannerLen,
spaceBetween: 10,
slidesOffsetBefore : -($('.swiper-num').width()),
watchSlidesProgress: true,
watchSlidesVisibility: true
});
avatarSwiperClone.params.control = avatarSwiper;
avatarSwiper.params.control = avatarSwiperClone;
}
}
if (Math.abs(this.startY) < $('.banner-top').height() + $('.avatar').outerHeight() + $('.head-tab').height()) {
$('.avatar-clone').hide();
}
});
... ... @@ -105,6 +129,7 @@ function setIndexAction() {
if (this.directionY === 1) {
$headTab.slideUp(1000);
}
$loadingTip.slideUp();
});
... ... @@ -165,6 +190,10 @@ function setIndexAction() {
}
*/
$('.avatar').each(function(key, item){
$(item).addClass('avatar-' + key);
});
// banner swiper 初始化
if ($('.banner-swiper').find('li').length > 1) {
new Swiper('.banner-swiper', {
... ... @@ -180,42 +209,18 @@ function setIndexAction() {
}
// 明星头像 swiper 初始化
// if (bannerLen > 1) {
// $('.avatar-swiper').each(function(key, item) {
// avatarSwiper[key] = new Swiper('.avatar-' + key, {
// loop: true,
// // loopedSlides: bannerLen,
// initialSlide: 2,
// centeredSlides: true,
// slidesPerView: 'auto',
// spaceBetween: 10,
// slidesOffsetBefore: '-' + $(item).find('li').not('.swiper-slide-visible').width() / 2,
// watchSlidesProgress: true,
// watchSlidesVisibility: true,
// observer: true,
// observeParents: true
// });
// });
// }
if (bannerLen > 1) {
avatarSwiper = new Swiper('.avatar', {
avatarSwiper = new Swiper('.avatar-1', {
loop: true,
// loopedSlides: bannerLen,
initialSlide: 2,
mode:'horizontal',
centeredSlides: true,
slidesPerView: 'auto',
loopedSlides: bannerLen,
spaceBetween: 10,
slidesOffsetBefore: -($('.avatar').find('li').not('.swiper-slide-visible').width() / 2),
slidesOffsetBefore : -($('.swiper-num').width()),
watchSlidesProgress: true,
watchSlidesVisibility: true,
observer: true,
observeParents: true
});
avatarSwiper[0].params.control = avatarSwiper[1];// 需要在Swiper2初始化后,Swiper1控制Swiper2
avatarSwiper[1].params.control = avatarSwiper[0];// 需要在Swiper1初始化后,Swiper2控制Swiper1
watchSlidesVisibility: true
});
}
// 明星动态头像左右滑动
... ... @@ -238,18 +243,21 @@ function setIndexAction() {
});
}
// 明星头像点击居中显示或跳转
$('.avatar-swiper li').on('click', function() {
if ($(this).hasClass('swiper-slide-active')) {
location.href = $(this).find('img').data('url');
} else {
avatarKey = $(this).index();
avatarSwiper[0].slideTo(avatarKey, 1000, false);
if(avatarSwiperClone) {
avatarSwiperClone.slideTo(avatarKey, 1000, false);
}
avatarSwiper.slideTo(avatarKey, 1000, false);
}
});
$('.rank-avatar').each(function(key, item) {
if ($(item).attr('data-avatar') !== '') {
setAvatar($(item));
... ... @@ -276,7 +284,15 @@ getIndexHtml = function() {
$starMain.html(data);
bannerLen = $('.avatar .swiper-slide').length;
$starMain.prepend($('.avatar-swiper').clone().addClass('avatar-clone').hide());
if ($('.avatar-clone')) {
$('.avatar-clone').remove();
}
$('.avatar li').each(function(){
setAvatar($(this).find('span'));
});
$starMain.before($('.avatar-swiper').clone().addClass('avatar-clone').hide());
// 限制标题字数
$('.cont-area').each(function() {
... ...
... ... @@ -114,15 +114,14 @@
.avatar-swiper {
overflow: hidden;
margin-top: 30px;
background: #000;
&.avatar-clone {
position: fixed;
left: 0;
top: 0;
margin-top: 86px;
margin-top: 0;
position: relative;
padding: 5px 0;
background: #000;
z-index: 9;
background: #000;
}
li {
... ... @@ -131,11 +130,12 @@
width: 110px;
height: 110px;
margin-top: 34px;
background: #282828;
img {
span {
display: block;
width: 100%;
height: 100%;
border-radius: 4px;
}
}
... ... @@ -373,6 +373,11 @@
font-size: 12px;
margin: 30px 0;
}
.swiper-num {
width: 55px;
display: none;
}
}
.star-index-bg {
... ...