custom.page.js 3.19 KB
var Swiper = require('yoho-swiper2');
var lazyLoad = require('yoho-jquery-lazyload');
var fastclick = require('yoho-fastclick');
var swiperClass;

require('../common');

$(function() {
    fastclick.attach(document.body);
    lazyLoad($('img.lazy'));

    // 头部banner轮播
    if ($('.banner-swiper').find('li').size() > 1) {
        new Swiper('.banner-swiper', {
            lazyLoading: true,
            lazyLoadingInPrevNext: true,
            loop: true,
            autoplay: 3000,
            autoplayDisableOnInteraction: false,
            paginationClickable: true,
            slideElement: 'li',
            pagination: '.banner-top .pagination-inner'
        });
    }

    // 小 banner
    $('.banner-center-swiper').each(function() {
        if ($(this).find('li').length > 1) {
            new Swiper(this, {
                preloadImages: false,
                lazyLoading: true,
                lazyLoadingInPrevNext: true,
                lazyLoadingOnTransitionStart: true,
                loop: true,
                autoplay: 3000,
                autoplayDisableOnInteraction: false,
                slideElement: 'li',
                paginationHide: true
            });
        }
    });

    // 热门品牌滑动
    if ($('.brands-swiper').find('li').length > 1) {
        new Swiper('.brands-swiper', {
            grabCursor: true,
            slidesPerView: 'auto',
            wrapperClass: 'brands-list',
            slideElement: 'li'
        });
    }

    // 推荐搭配滑动
    if ($('.recommend-swiper').find('li').length > 1) {
        new Swiper('.recommend-swiper', {
            grabCursor: true,
            slidesPerView: 'auto',
            wrapperClass: 'recommend-list',
            slideElement: 'li'
        });
    }

    // 潮品话题轮播
    if ($('.trend-topic-swiper').find('li').size() > 1) {
        new Swiper('.trend-topic-swiper', {
            loop: true,
            autoplay: 3000,
            autoplayDisableOnInteraction: false,
            paginationClickable: true,
            slideElement: 'li',
            pagination: '.trend-topic-content .pagination-inner'
        });
    }

    // 新人专享轮播
    if ($('.fresh-list-swiper').find('li').size() > 1) {
        new Swiper('.fresh-list-swiper', {
            lazyLoading: true,
            lazyLoadingInPrevNext: true,
            grabCursor: true,
            slidesPerView: 'auto',
            slideElement: 'li',
            watchSlidesVisibility: true
        });
    }

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