star.page.js 1.74 KB
/**
 * 星潮教室首页
 * @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 avatarSwiper, avatarKey, $this, $title, $cont;

lazyLoad($('img.lazy'));
ellipsis.init();

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-info').find('li').length > 0) {
    // 限制标题字数
    $('.star-article').each(function() {
        $this = $(this);
        $title = $this.find('.article-title');
        $cont = $this.find('p');

        $title[0].mlellipsis(2);
        $cont[0].mlellipsis(3);
    });
}

$('body').addClass('star-index-bg');

$('.avatar-swiper li').not('.swiper-slide-active').on('click', function() {
    avatarKey = $(this).index();
    avatarSwiper.slideTo(avatarKey, 1000, false);
});

$('.swiper-slide-active').on('click', function() {
    location.href = $(this).find('img').data('url');
});