fav.js 1.55 KB
/**
 * 个人中心--收藏
 * @author: chenglong<chenglong.wang@yoho.cn>
 * @date: 2015/11/12
 */

var $ = require('jquery'),
    Hammer = require('yoho.hammer'),
    lazyLoad = require('yoho.lazyload'),
    Swiper = require('yoho.iswiper');

//导航
var $navLi = $('#fav-tab > li'),
    $favContainer = $('.fav-content');

var $curContainer = $favContainer.children('.fav-type').first();//保存当前显示的$favContainer

var favTabHammer;

//轮播图
var $swiperList = $('.swiper-container'),
    swiperArray = [],
    swiperObj = {};

//lazyLoad();

favTabHammer = new Hammer(document.getElementById('fav-tab'));
favTabHammer.on('tap', function(e) {
    var $cur = $(e.target).closest('li'),
        index;

    if ($cur.length === 0 || $cur.hasClass('active')) {
        return;
    }

    index = $cur.index();

    $navLi.filter('.active').removeClass('active');
    $cur.addClass('active');

    $curContainer.addClass('hide');
    $curContainer = $favContainer.children(':eq(' + index + ')').removeClass('hide');

    if (index === 1) {
        //导航
        for (var i = 0; i < $swiperList.length; i++) {
            var id = $swiperList.eq(i).attr('data-id');
            swiperObj[id] = new Swiper('#swiper-container-' + id, {
                slidesPerView: 'auto',
                grabCursor: true,
                slideElement: 'li',
                wrapperClass: 'swiper-wrapper-' + id,
                lazyLoading: true,
                watchSlidesVisibility: true
            });
        }

    }
});