-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcarotte.nav.js
58 lines (45 loc) · 1.66 KB
/
carotte.nav.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
/* [URL] */
;(function($, window, document, undefined) {
var r = $.carotte.slideshow;
r.nav = {
options : {}
};
$.fn.nav = function(options) {
options = $.extend({}, r.nav.options, options);
return this.each(function(){
var self = this,
container = $(self),
navigation = container.closest('.allCarotte').find('.navCarotte'),
childs = container.children(),
dataW = container.data('width'),
numberChild = childs.length;
container.addClass('navRas');
container.children().eq(0).addClass('activeSlide');
container.children().each(function(e){
$(this).attr('data-left', dataW*e);
});
navigation.each(function(){
$(this).prepend('<div class="navMultiple"/>');
});
var navMultiple = navigation.find(".navMultiple");
for(var i = numberChild; i>=1; i--) {
navMultiple.prepend('<button data-slide="'+(i-1)+'">'+i+'</button>');
}
navMultiple.find('button:eq(0)').addClass('active');
navMultiple.find('button').each(function(e){
var slide = $(this).data('slide');
$(this).click(function(){
navMultiple.find('.active').removeClass('active');
$(this).addClass('active');
var childSelected = container.children().eq(slide),
leftContainer = childSelected.data('left');
container.find('.activeSlide').removeClass('activeSlide');
childSelected.addClass('activeSlide');
container.animate({
'margin-left': -leftContainer
})
})
});
});
};
})(jQuery, window, document);