-
Notifications
You must be signed in to change notification settings - Fork 0
/
slider.js
148 lines (115 loc) · 2.95 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
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
var slider = document.getElementById("slider");
slider.style.position = "relative";
var slides = slider.getElementsByClassName("slide");
var pocet = slides.length;
function posunSlideDalsi(stary,aktualny,novy,rychlost)
{
$(stary).fadeOut(rychlost,"swing");
$(stary).promise().done(function()
{
$(stary).removeAttr('id');
$(aktualny).attr('id','slide-prioritny');
$(novy).attr('id','slide-nasledujuci');
stary.style.display = "";
done=true;
});
}
function posunSlidePredosli(stary,aktualny,novy)
{
$(stary).fadeOut(500,"swing");
$(stary).promise().done(function()
{
$(stary).attr('id','slide-nasledujuci');
$(aktualny).attr('id','slide-prioritny');
stary.style.display = "";
done=true;
});
}
var timer = function()
{
if (!$(slider).is(':hover'))
$('#nasledujuci').trigger('click');
};
var index = 0;
var aktind = 0;
var znova = false;
var cas = 5000;
var interval;
var done = true;
var obrazok = slides[index].getElementsByTagName("img")[0];
if($(slides[index].getElementsByClassName("slide-obrazok")[0]).css("float")!="left")
interval = setInterval(timer,cas);
$('#nasledujuci').click(function()
{
if(done==true)
{
done = false;
index++;
if(index==pocet)
index = 0;
aktind = index;
var aktualny = slides[aktind];
var novy;
if(aktind+1==pocet)
novy = slides[0];
else
novy = slides[aktind+1];
var stary;
if(aktind-1==-1)
stary = slides[pocet-1];
else
stary = slides[aktind-1];
posunSlideDalsi(stary, aktualny, novy, 500);
clearInterval(interval);
if($(slides[index].getElementsByClassName("slide-obrazok")[0]).css("float")!="left")
interval = setInterval(timer,cas);
}
});
$('#predchadzajuci').on('click', function()
{
if(done==true)
{
done = false;
index--;
if(index==-1)
index = pocet-1;
aktind = index;
var aktualny = slides[aktind];
$(aktualny).attr('id','slide-nasledujuci');
var novy;
if(aktind-1==-1)
novy = slides[pocet-1];
else
novy = slides[aktind-1];
$(novy).removeAttr('id');
var stary;
if(aktind+1==pocet)
stary = slides[0];
else
stary = slides[aktind+1];
posunSlidePredosli(stary, aktualny, novy);
clearInterval(interval);
if($(slides[index].getElementsByClassName("slide-obrazok")[0]).css("float")!="left")
interval = setInterval(timer,cas);
}
});
$(window).resize(function()
{
obrazok = slides[index].getElementsByTagName("img")[0];
if($(slides[index].getElementsByClassName("slide-obrazok")[0]).css("float")=="left")
{
posunSlideDalsi(slides[index+1==pocet ? index : index+1], slides[index=0],slides[1], 0);
clearInterval(interval);
znova = true;
}
else
{
if(znova)
{
interval = setInterval(timer,cas);
znova = false;
}
}
});
document.getElementById("predchadzajuci").style.display = "block";
document.getElementById("nasledujuci").style.display = "block";