public.js 3.71 KB
/*
 * 首页 JS
 * @author xuqi/liuyue
 * @date: 2015/7/15
 */

var $ = require('jquery'),
    swiper = require('yoho-idangerous.swiper'),
    lazyLoad = require('./common/lazyload'),
    bannerSwiper,
    hotBrandsSwiper,
    recommendSwiper,
    trendTopicSwiper,
    goodsSwiper;

require('./common/maybe-like');

//lazyload
lazyLoad();

//点击首页汉堡menu图标,滑出侧栏导航
$('.nav-btn').on('click', function(event) {
    if (!$(this).hasClass('menu-open')) {
        $('.mobile-wrap').addClass('menu-open');
        $('.overlay').addClass('show');
        //设置boy高宽,页面不能上下滑动
        $('body').css({
            height: $(window).height(),
            width: '100%',
            overflow: 'hidden'
        });
    }
    event.stopPropagation();
});

//点击页面主体,收起侧栏导航及二级导航
$('.mobile-wrap').on('click', function() {
    if ($(this).hasClass('menu-open')) {
        $('.mobile-wrap').removeClass('menu-open');
        $('.overlay').removeClass('show');
        $('.sub-nav').removeClass('show');
        $('body').css({
            height: 'auto',
            overflow: 'auto'
        })
    }
});

//点击一级导航,弹出二级导航
$('.side-nav').on('click', 'li', function() {
    if ($(this).find('.sub-nav').size() > 0) {
        $('.sub-nav').removeClass('show');
        $(this).find('.sub-nav').addClass('show');
    }
});

//返回一级导航,收起二级导航
$('.sub-nav').each(function() {
    $(this).find('li').eq(0).on('click', function() {
        $('.sub-nav').removeClass('show');
        event.stopPropagation();
    });
});

//头部banner轮播
if ($('.banner-swiper').find('li').size() > 1) {
    bannerSwiper = new swiper('.banner-swiper', {
        loop: true,
        autoplay: 3000,
        autoplayDisableOnInteraction: false,
        paginationClickable: true,
        slideElement: 'li',
        pagination: '.banner-top .pagination-inner',
        onSlideChangeStart: function() {
            lazyLoad($('.banner-swiper .swiper-slide').eq(bannerSwiper.activeIndex).find('img'));
        }
    });
};

//热门品牌滑动
hotBrandsSwiper = new swiper('.brands-swiper', {
    grabCursor: true,
    slidesPerView: 'auto',
    wrapperClass: 'brands-list',
    slideElement: 'li'
});

//推荐搭配滑动
recommendSwiper = new swiper('.recommend-swiper', {
    grabCursor: true,
    slidesPerView: 'auto',
    wrapperClass: 'recommend-list',
    slideElement: 'li'
});

//潮品话题轮播
if ($('.trend-topic-swiper').find('li').size() > 1) {
    trendTopicSwiper = new swiper('.trend-topic-swiper', {
        loop: true,
        autoplay: 3000,
        autoplayDisableOnInteraction: false,
        paginationClickable: true,
        slideElement: 'li',
        pagination: '.trend-topic-content .pagination-inner',
        onSlideChangeStart: function() {
            lazyLoad($('.trend-topic-swiper .swiper-slide').eq(trendTopicSwiper.activeIndex).find('img'));
        }
    });
};

//潮流上装/经典裤装等轮播
$('.category-swiper').each(function(i, index) {
    var swiperClass = 'category-swiper' + i;
    $(this).addClass(swiperClass);
    if ($('.' + swiperClass).find('.swiper-slide').size() > 1) {
        goodsSwiper = new swiper('.' + swiperClass, {
            loop: true,
            autoplay: 3000,
            autoplayDisableOnInteraction: false,
            paginationClickable: true,
            slideElement: 'li',
            pagination: '.' + swiperClass + ' .pagination-inner'
        });
    }
});


//回到顶部
$('.back-to-top').bind('touchstart', function(e) {
    e.preventDefault();
    $(window).scrollTop(0);
});

//关闭头部下载浮层
$('.header-download').on('click', '.close-btn', function() {
    $(this).parent().remove();
});