accordion.js 907 Bytes
var Slide = require('./yohoui/YH.slide');
var $ = require('yoho-jquery');

var $contain = $('.slide-accordion');
var $item = $contain.find('li');

var width = $item.width(),
    spn = parseInt($('.home-page').width(), 10) === 1150 ? (120 + 5) : (102 + 5),
    slide;

function switchfun(to) {
    $item.each(function(index) {
        $(this).css('zIndex', index);
        if (index <= to) {
            $(this).stop().animate({
                left: index * spn
            }, 400);
        } else {
            $(this).stop().animate({
                left: (to) * spn + width + spn * (index - to - 1)
            }, 400);
        }
    });
}

switchfun(0);

slide = new Slide({
    length: 5,
    loop: false,
    auto: false,
    timeout: 2,
    index: 0
});

slide.on('change', function(data) {
    switchfun(data.to);
});

$item.mouseover(function() {
    slide.go($(this).index());
});

slide.init();