accordion.js
801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var Slide = require('./yohoui/YH.slide');
var $ = require('yoho.jquery');
var $contain = $('.slide-list', '.slide-accordion');
var $item = $contain.find('li');
var $width = 650;
var slide;
function switchfun(to) {
$item.each(function(index) {
if (index <= to) {
$(this).stop().animate({
left: index * (120 + 5)
});
} else {
$(this).stop().animate({
left: (to) * (120 + 5) + $width + (120 + 5) * (index - to - 1)
});
}
});
}
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();