-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiSlider.js
More file actions
203 lines (191 loc) · 8.77 KB
/
Copy pathtiSlider.js
File metadata and controls
203 lines (191 loc) · 8.77 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
Document : tiSlider.js
Created on : 30 mars 2012, 10:23:20
Author : Morgan Juillard Mancino
Description:
Javascript of tiSlider, a jquery plugin create by Tillid
Fell free to customize the design!
*/
(function($) {
$.fn.sliderBox = function(settings) {
if (!settings["width"])
settings["width"] = 910;
alert(settings["width"])
var elems = $(this).children('ul').children('li');
var next = $(this).children("ul").children(":eq(0)");
var images = $(this).children(".slider_image");
var tmpVal = 0;
$(this).children('ul').attr("alt", "unfree");
$(this).children('ul').attr("id", "timer");
/*
* configuration of the width and height of the slider and images
*/
tmpVal = parseInt($(images).width()) + parseInt($(images).css("borderLeftWidth").replace("px", "")) + parseInt($(images).css("borderRightWidth").replace("px", ""));
tmpVal += parseInt($(this).children('ul').width()) + parseInt($(this).children('ul').css("borderLeftWidth").replace("px", "")) + parseInt($(this).children('ul').css("borderRightWidth").replace("px", ""))
$(images).width(settings["width"] - tmpVal);
$(this).width(settings["width"]);
$(this).height($(this).children("ul").height());
$(this).children(".slider_image").height($(this).children("ul").height() - parseInt($(images).css("borderBottomWidth").replace("px", "")) - parseInt($(images).css("borderTopWidth").replace("px", "")));
/*
* Configuration of the images margins.
*/
$(images).children("img").each(function(){
$(this).load(function() {
$(this).css("marginLeft", ($(this).parent().width() - $(this).width()) / 2 + "px");
$(this).css("marginTop", ($(this).parent().height() - $(this).height()) / 2 + "px");
});
});
/*
* Add the div necessary for the menu
*/
$(elems).each(function(){
$(this).html('<div class="slider_menu">' + $(this).html() + '</div><div class="slider_arrow"></div>');
});
/*
* Configuration of the arrow margin.
*/
tmpVal = $(elems).width() - 49;
$(elems).children(".slider_arrow").css("marginLeft", tmpVal);
/*
* initialization of the first arrow
*/
$(next).attr("alt", "curent");
$(next).children('.slider_menu').children().animate({
paddingLeft: '+=20'
}, 75, function() {
});
$(next).children('.slider_arrow').animate({
marginLeft: '+=25'
}, 100, function() {
$(this).parent().parent().attr('alt', 'free');
});
/*
* initialization of the first image
*/
$(images).children().hide();
$(images).children('img:eq(0)').fadeIn(100, function() {
});
/*
* Function call by the timer to change the arrow and the images.
*/
window.setInterval(function(){
var list = $('.slider').children('ul');
if ($(list).attr('id') == 'timer')
{
$(list).children('li').each(function(){
if ($(this).parent().attr('alt') != 'free')
return;
var tmpVal = parseInt($(list).children("li").width()) - 49;
/*
* Test if the li is the "current tab" (display with the arrow).
* hide the arrow, show the arrow on the next li and change the image
*/
if ($(this).attr('alt') == "curent")
{
var images = $(this).parent("ul").parent("div").children(".slider_image");
var next = $(this).next();
if ($(this).nextAll().length == 0)
next = $(this).parent().children("li:eq(0)");
$(this).parent().attr('alt', "unfree");
$(this).attr('alt', "");
/*
* Animation oh the arraows
*/
$(this).children(".slider_menu").children().animate({
paddingLeft: '-=20'
}, 50, function() {
// Animation complete.
});
$(this).children('.slider_arrow').animate({
marginLeft: tmpVal
}, 50, function() {
});
$(next).attr("alt", "curent");
$(next).children('.slider_menu').children().animate({
paddingLeft: '+=20'
}, 75, function() {
});
$(next).children('.slider_arrow').animate({
marginLeft: tmpVal + 25
}, 100, function() {
$(this).parent().parent().attr('alt', 'free');
});
/*
* Animation of the images
*/
$(images).children().fadeOut(100, function() {
});
$(images).children(":eq(" + $(next).prevAll().length + ")").fadeIn(100, function() {
});
}
});
}
}, 3000);
/*
* Function call to show an arraow and change the image.
* block the
* hide the previous curent tab and show the new.
*/
over = function() {
var tmpVal = parseInt($(this).width()) - 49;
if ($(this).parent().attr('alt') == 'free')
{
$(this).parent().attr('id', "notimer");
var list = $(this).parent("ul").children();
var images = $(this).parent("ul").parent("div").children(".slider_image");
if ($(this).attr('alt') != "curent")
{
$(this).parent().attr('alt', "unfree");
/*
* hide all the arrows
*/
$(list).each(function(){
if ($(this).attr('alt') == "curent")
{
$(this).attr('alt', "");
$(this).children(".slider_menu").children().animate({
paddingLeft: '-=20'
}, 50, function() {
// Animation complete.
});
$(this).children('.slider_arrow').animate({
marginLeft: tmpVal
}, 50, function() {
});
$(this).attr('alt', "");
}
});
/*
* Show the curent arrow
*/
$(this).attr('alt', "curent");
$(this).children('.slider_menu ').children().animate({
paddingLeft: '+=20'
}, 75, function() {
});
$(this).children('.slider_arrow').animate({
marginLeft: tmpVal + 25
}, 100, function() {
$(this).parent().parent().attr('alt', 'free');
});
/*
* Animation of the images
*/
$(images).children().fadeOut(100, function() {
});
$(images).children(":eq(" + $(this).prevAll().length + ")").fadeIn(100, function() {
});
}
}
return false;
}
/*
* Function call for return to the automatic animation;
*/
out = function() {
$(this).parent().attr('id', "timer");
return false;
}
$(elems).hover(over, out);
}
})(jQuery);