|
@@ -7,28 +7,40 @@ exports.init = function(selector) { |
|
@@ -7,28 +7,40 @@ exports.init = function(selector) { |
7
|
var $imgBrand = $(selector);
|
7
|
var $imgBrand = $(selector);
|
8
|
var slider = $imgBrand.unslider({
|
8
|
var slider = $imgBrand.unslider({
|
9
|
autoplay: true,
|
9
|
autoplay: true,
|
10
|
- delay: 3000,
|
|
|
11
|
- arrows: {
|
|
|
12
|
-
|
|
|
13
|
- },
|
|
|
14
|
- nav: false,
|
|
|
15
|
- animate: 'fade'
|
10
|
+ delay: 5000,
|
|
|
11
|
+ arrows: false,
|
|
|
12
|
+ nav: false
|
16
|
});
|
13
|
});
|
17
|
var imgBrandNum = $imgBrand.find('li').length;
|
14
|
var imgBrandNum = $imgBrand.find('li').length;
|
18
|
- var rows = imgBrandNum / 3;
|
15
|
+ var cols = imgBrandNum / 3;
|
|
|
16
|
+ var changeSliderTimeout;
|
19
|
|
17
|
|
20
|
if (!($imgBrand.find('li').length % 3)) {
|
18
|
if (!($imgBrand.find('li').length % 3)) {
|
21
|
- rows -= 1;
|
19
|
+ cols -= 1;
|
22
|
}
|
20
|
}
|
23
|
|
21
|
|
24
|
$imgBrand.find('li:nth-child(3n)').css('margin-right', 0);
|
22
|
$imgBrand.find('li:nth-child(3n)').css('margin-right', 0);
|
25
|
|
23
|
|
26
|
slider.on('unslider.change', function(event, index) {
|
24
|
slider.on('unslider.change', function(event, index) {
|
27
|
- if (index > rows) {
|
|
|
28
|
- slider.unslider('animate:' + imgBrandNum);
|
|
|
29
|
- slider.unslider('animate:first');
|
25
|
+ clearTimeout(changeSliderTimeout);
|
|
|
26
|
+ if (index >= cols) {
|
|
|
27
|
+ changeSliderTimeout = setTimeout(function() {
|
|
|
28
|
+ slider.unslider('animate:first');
|
|
|
29
|
+ }, 4999);
|
30
|
}
|
30
|
}
|
31
|
});
|
31
|
});
|
32
|
|
32
|
|
33
|
- // TODO: 手动点击左右
|
33
|
+ $('.img-brand-switch').on('click', '.prev', function() {
|
|
|
34
|
+ if (slider.data('unslider').current > cols || slider.data('unslider').current <= 0) {
|
|
|
35
|
+ slider.unslider('animate:' + cols);
|
|
|
36
|
+ } else {
|
|
|
37
|
+ slider.unslider('prev');
|
|
|
38
|
+ }
|
|
|
39
|
+ }).on('click', '.next', function() {
|
|
|
40
|
+ if (slider.data('unslider').current >= cols) {
|
|
|
41
|
+ slider.unslider('animate:first');
|
|
|
42
|
+ } else {
|
|
|
43
|
+ slider.unslider('next');
|
|
|
44
|
+ }
|
|
|
45
|
+ });
|
34
|
}; |
46
|
}; |