nav.js 774 Bytes
var $ = require('yoho-jquery'),
    IScroll = require('yoho-iscroll');

var defaultOpt = {
    navClass: '.outlet-nav'
};

// nav 滚动
function initNavScroll(opt) {
    var $navBox,
        iScroll;

    $.extend(opt || {}, defaultOpt);

    $navBox = $(opt.navClass);

    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);
    }

    $.each($navBox, function(index) {
        iScroll = new IScroll($navBox[index], {
            scrollX: true,
            scrollY: false
        });
    });

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

module.exports = initNavScroll;