Версия, подходяща за принтиране

Оригинлната версия може да видите тук

Автоматично превключване на табове ?
Публикувано от Moreny на: 08.08.2008 17:00
Здравейте,
Днес намерих един сайт в които има урок как се слага на wordpress табове с теми от определена категория.
Ето го адреса на урока с кода

Въпроса ми е как може да се направи тези табове да се превключват автоматично. Тоест 1 да се показва за 10 сек. след това 2, и така като стигне до 4 да почва пак от 1.

Kакто е да речем : http://www.brianlitzinger.com/code/tabs/#

Може би нещо в JavaScripta трябва да се допише ? В момента табовете само ръчно се превключват. Ако може да стане автоматично през определен интервал от време ще е супер.

Благодаря Ви!

Публикувано от G9M29 на: 08.08.2008 17:17
CODE
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Tab slideshow Demo<
/title>
</
head>

<
body>
<
script type="text/javascript" src="scripts/jquery.js"></script>
<
script type="text/javascript">

/* ------
  • Script based on/inspired by: http://www.bigbold.com/snippets/posts/show/1068
  • re-written by Brian Litzinger to use the jQuery library
  • cookie functions from: http://www.quirksmode.org/js/cookies.html
------- */

f
unction tabs_index(){

   
total_slides = 5;
   
show_timer = 7000;
   
show_count = show_timer/1000;
   
cookie = readCookie('rememberTab');
    $
("div.tabContent").hide();
    $
("div#tab1").show();   
    $
("li#tabLink1").addClass('active');           
   
   
if(cookie == null){
       
start_slideshow(1, total_slides, show_timer);
       
document.getElementById('rememberTab').checked = false;
   
} else {
        $
("div.tabContent:visible").hide();
        $
("li.tabLink").removeClass('active');
        $
("div#tab"+cookie).show();
        $
("li#tabLink"+cookie).addClass('active');
       
document.getElementById('rememberTab').checked = false;
       
write_current_tab(cookie);
   
}
   
    $
("li#tabLink1 a").click(function(){
        $
("div.tabContent:visible").hide();
        $
("li.tabLink").removeClass('active');
        $
("div#tab1").show();
        $
("li#tabLink1").addClass('active');
       
document.getElementById('rememberTab').value = 1;   
       
document.getElementById('rememberTab').checked = false;   
       
write_current_tab(1);
       
stop_all();
   
});
    $
("li#tabLink2 a").click(function(){
        $
("div.tabContent:visible").hide();
        $
("li.tabLink").removeClass('active');
        $
("div#tab2").show();
        $
("li#tabLink2").addClass('active');
       
document.getElementById('rememberTab').value = 2;
       
document.getElementById('rememberTab').checked = false;
       
write_current_tab(2);
       
stop_all();
   
});
    $
("li#tabLink3 a").click(function(){
        $
("div.tabContent:visible").hide();
        $
("li.tabLink").removeClass('active');
        $
("div#tab3").show();
        $
("li#tabLink3").addClass('active');
       
document.getElementById('rememberTab').value = 3;
       
document.getElementById('rememberTab').checked = false;
       
write_current_tab(3);
       
stop_all();
   
});
    $
("li#tabLink4 a").click(function(){
        $
("div.tabContent:visible").hide();
        $
("li.tabLink").removeClass('active');
        $
("div#tab4").show();
        $
("li#tabLink4").addClass('active');
       
document.getElementById('rememberTab').value = 4;
       
document.getElementById('rememberTab').checked = false;
       
write_current_tab(4);
       
stop_all();
   
});
    $
("li#tabLink5 a").click(function(){
        $
("div.tabContent:visible").hide();
        $
("li.tabLink").removeClass('active');
        $
("div#tab5").show();
        $
("li#tabLink5").addClass('active');
       
document.getElementById('rememberTab').value = 5;
       
document.getElementById('rememberTab').checked = false;
       
write_current_tab(5);
       
stop_all();
   
});
    $
("#rememberTab").click(function(){
       
textValue = document.getElementById('rememberTab').value;
       
createCookie('rememberTab', textValue, 365);
       
set_current_tab(textValue);
       
stop_all();
   
});       
}
   
function write_current_tab(frame){
   
newCookie = readCookie('rememberTab');
   
tabHTML = $("li#tabLink"+frame+" a").html();
   
currentTab = $("li#tabLink"+newCookie+" a").html();
   
if(cookie != frame && cookie != null){
       
newHTML = "Make <b>"+ tabHTML +"</b> my default tab. My default tab is currently <b>"+ currentTab +"</b>.";
   
} else if(cookie != null) {
       
newHTML = "Your default tab is currently <b>"+ currentTab +"</b>.";
   
} else {
       
newHTML = "Make <b>"+ tabHTML +"</b> my default tab.";
   
}
    $
("div#settings span").html(newHTML);
}

function set_current_tab(frame){
   
newCookie = readCookie('rememberTab');
   
currentTab = $("li#tabLink"+newCookie+" a").html();
   
newHTML = "Your default tab is now set to <b>"+ currentTab +"</b>.";
    $
("div#settings span").html(newHTML);
}
   
function start_slideshow(start_frame, end_frame, delay) {
   
interval1 = setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
   
count_down(show_count);
}

function timer(frame, start_frame, end_frame, delay){
   
interval2 = setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay);
}
                       
function switch_slides(frame, start_frame, end_frame, delay) {
   
write_current_tab(frame);
   
return (function() {   
        $
('div#tab'+frame).hide();
        $
('li#tabLink'+frame).removeClass('active');
       
if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
        $
('div#tab'+frame).show();
        $
('li#tabLink'+frame).addClass('active');
       
document.getElementById('rememberTab').checked = false;
       
document.getElementById('rememberTab').value = frame;
       
timer(frame, start_frame, end_frame, delay);
       
count_down(show_count);
   
})


function count_down(count){
   
count--;
    $
("div#tabCounter").html(count);
   
interval3 = setTimeout("count_down("+count+")", 1000);
   
if(count == 0){
       
count = show_count;
       
clearTimeout(interval3);
   
}
}

function stop_all() {
    $
("div#tabCounter").hide();
   
clearTimeout(interval1);
   
clearTimeout(interval2);
   
clearTimeout(interval3);
   
cookie = readCookie('rememberTab');
}

function createCookie(name,value,days){
   
if (days){
       
var date = new Date();
       
date.setTime(date.getTime()+(days*24*60*60*1000));
       
var expires = "; expires="+date.toGMTString();
   
}
   
else var expires = "";
   
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name){
   
var nameEQ = name + "=";
   
var ca = document.cookie.split(';');
   
for(var i=0;i < ca.length;i++){
       
var c = ca[i];
       
while (c.charAt(0)==' ') c = c.substring(1,c.length);
       
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   
}
   
return null;
}
function eraseCookie(name){
   
createCookie(name,"",-1);
}

$
(document).ready(function(){
   
tabs_index();
});

</
script>

<
style type="text/css">

div.tabs{
   
font-family: arial, helvetica, sans-serif;
   
font-size: 12px;
   
position: relative;
   
width: 400px;
   
height: 300px;
}
ul.tabLinks{
   
width:100%;
   
margin:0;
   
padding: 0;   
   
list-style: none;
}
ul.tabLinks li{
   
float:left;
   
padding:0;
}
ul.tabLinks a:link,
ul.tabLinks a:visited,
ul.tabLinks a:active,
ul.tabLinks a:hover{
   
text-align: center;
   
padding: 5px;
   
display: block;
   
background: #fff url(images/bg_news_tab.gif) 0 100% repeat-x;
   
color: #5f5e5e;
   
font-weight: bold;
   
text-decoration:none;
   
margin-right: 2px;
   
border-left: 1px solid #d9e0ec;
   
border-right: 1px solid #d9e0ec;
   
border-top: 1px solid #d9e0ec;
}
ul.tabLinks a:hover{
   
color: #000;
}
div.tabs div.tabContent {
   
clear: both;
   
color: #000;
   
padding: 10px;
   
border-left: 1px solid #d9e0ec;
   
border-right: 1px solid #d9e0ec;
   
border-bottom: 1px solid #d9e0ec;
   
background: #fff url(images/bg_news.gif) 0 0 repeat-x;
}
ul.tabLinks li.active a:link,
ul.tabLinks li.active a:visited,
ul.tabLinks li.active a:active,
ul.tabLinks li.active a:hover{
   
color:#003082;
   
background-image: none;
   
background-color: #d9e0ec;
   
border-left: 1px solid #d9e0ec;
   
border-right: 1px solid #d9e0ec;
   
border-top: 1px solid #d9e0ec;
}
div.tabs div.tabContent a:link,
div.tabs div.tabContent a:visited,
div.tabs div.tabContent a:active {
   
color: #003082;
}
div.tabContent a:hover {
   
color: #000;
}

#tabCounter {
   
display: block;
   
position: absolute;
   
top: 6px;
   
right: 0;
   
color:#baaf9a;
    }
   
#settings {
   
display: block;
   
color:#9a9181;
    }

</
style>

</
body>

<
div class="tabs">
    <
ul class="tabLinks">
        <
li id="tabLink1" class="tabLink"><a href="#">News</a></li>
        <
li id="tabLink2" class="tabLink"><a href="#">Highlights</a></li>
        <
li id="tabLink3" class="tabLink"><a href="#">Events</a></li>
        <
li id="tabLink4" class="tabLink"><a href="#">Places</a></li>

        <
li id="tabLink5" class="tabLink"><a href="#">Profiles</a></li>
    </
ul>
   
    <
div id="tabCounter">.</div>   
   
    <
div id="tab1" class="tabContent">
       
Tab 1
    </
div>
   
    <
div id="tab2" class="tabContent">
       
Tab 2
    </
div>

   
    <
div id="tab3" class="tabContent">
       
Tab 3
    </
div>
   
    <
div id="tab4" class="tabContent">
       
Tab 4
    </
div>
   
    <
div id="tab5" class="tabContent">
       
Tab 5
    </
div>
   
    <
div id="settings">

        <
input type="checkbox" name="rememberTab" value="1" id="rememberTab" />
        <span><
/span>
    </
div>
</
div>

</
html>

То това си го имаше в сорс-а на страницата!

---------------------------
Свободата е правото на Избор ! / ИНТЕРНЕТ /
Публикувано от Moreny на: 08.08.2008 17:43
Да аз го пробвах него още преди да пиша, но не става не сработва. Мисля, че трябва да се промени малко за да стане за скрипт които съм дал за Wordpress.

Моля те, ако може да отделиш малко време и да го пробваш да кажеш как точно ще стане на въпросния скрипт за Wordpress. Малко трябва да се пипне, но хич ме няма в JavaScript-та.

Много ти благодаря!


MYTECH.BG