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

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

var $width = $item.width();
var $spn = parseInt($('.home-page').width()) === 1150 ? (120 + 5) : (102 + 5);
var 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: 3
});

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

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

slide.init();