banner.js
1.64 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* author: chenglong
*/
var Slide = require('../../plugins/yohoui/YH.slide');
var $ = require('yoho-jquery');
var $contain = $('.sale-list-banner');
var $item = $contain.find('li');
var index = 0;
var pagationStr = '';
var pagationBoxStr = '';
var i;
var current = true;
var slide;
for (i = 0; i < $item.length; i++) {
if (i === 0) {
pagationStr += '<span class="active"></span>';
} else {
pagationStr += '<span></span>';
}
}
pagationBoxStr = '<div class="sale-list-pagation">' +
'<div class="slide-pagination-inner"><div class="slide-shade"></div><div>' +
pagationStr + '</div></div></div>';
if ($item.length > 1) {
$contain.append($(pagationBoxStr));
}
slide = new Slide({
length: $item.length,
loop: true,
auto: true,
timeout: 2,
index: 0
});
if ($item.length > 1) {
slide.on('change', function(data) {
if (current) {
current = false;
} else {
return;
}
index++;
$('.sale-list-pagation').find('span').removeClass('active');
$item.eq(data.from).animate({
opacity: 0
}, 300);
$item.eq(data.to).css({
zIndex: index
}).animate({
opacity: 1
}, 300, function() {
current = true;
});
$('.sale-list-pagation').find('span').eq(data.to).addClass('active');
});
}
$contain.hover(function() {
if (current) {
slide.pause();
}
}, function() {
slide.resume();
});
$('.sale-list-pagation span').click(function() {
var indexCount = $(this).index();
if (current) {
slide.go(indexCount);
}
});
slide.init();