home.js 930 Bytes
var $ = require('yoho-jquery'),
    IScroll = require('yoho-iscroll'),
    lazyLoad = require('yoho-jquery-lazyload');

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

// nav 滚动
function initNavScroll() {
    var $navBox = $('.outlet-nav'),
        $lis = $navBox.find('li'),
        iScroll;

    function scroll(ele) {
        var offset;

        ele = ele || $navBox.find('li').eq(0)[0];
        offset = -($navBox.find('ul').width() - 20) / 2;

        setTimeout(function() {
            iScroll.scrollToElement(ele, 400, offset);
        }, 1);
    }

    iScroll = new IScroll($navBox[0], {
        scrollX: true,
        scrollY: false
    });
    $navBox.on('click', 'li', function() {
        var $this = $(this); // eslint-disable-line
        var i = $this.index();

        $lis.eq(i).addClass('active').siblings().removeClass('active');
        scroll($this[0]);
    });

    scroll($navBox.find('.active')[0]);
}

initNavScroll();