-
Notifications
You must be signed in to change notification settings - Fork 0
/
slider.js
63 lines (58 loc) · 1.58 KB
/
slider.js
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
(function ($) {
var index = 0;
var n;
var setWidth = function () {
$('.slide-wrapper li').css('height','0')
$('.slide-wrapper').css({
'width': $('.banner').width()*(n+1) + 'px'
});
console.log("$('.slide-wrapper').css('width'): "+$('.slide-wrapper').css('width'))
console.log("$('.banner').width()*6 + 'px': "+$('.banner').width()*(n+1) + 'px')
console.log($('.slide-wrapper').css('width'))
$('.slide-wrapper li').css({
'width': $('.banner').width() + 'px'
});
console.log("$('.banner').width() + 'px': "+$('.banner').width() + 'px')
console.log("$('.slide-wrapper li').width(): "+$('.slide-wrapper li').width())
console.log('------------------------')
$('.slide-wrapper li').css('height','auto')
}
var goPrev = function () {
if(index == 0) {
index = n;
$('.slide-wrapper').css({
'margin-left': -$('.banner').width()*index + 'px'
})
}
index--;
$('.slide-wrapper').animate({
'margin-left': -$('.banner').width()*index + 'px'
},1000);
}
var goNext = function () {
if(index == n) {
index = 0;
$('.slide-wrapper').css({
'margin-left': '0'
})
}
index++;
$('.slide-wrapper').animate({
'margin-left': -$('.banner').width()*index + 'px'
}, 1000);
}
$.fn.extend({
slider: function (opts) {
var self =$(this);
n = $('.slide-wrapper .slide').length;
$('.slide-wrapper').html($('.slide-wrapper').html() + $('.slide-wrapper .slide').first().prop('outerHTML'));
setWidth();
$(window).resize(function () {
setWidth();
});
setInterval(function () {
goPrev();
},3000);
}
});
})(jQuery);