forked from jadonk/bone101
-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.js
48 lines (42 loc) · 1.16 KB
/
index.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
var slides = $('#slides').children();
document.onkeydown = onkd;
var timeout = setTimeout(slideNext, 60000);
function onkd(event) {
var e = event.keyCode;
switch(e) {
case 37:
slidePrev();
break;
case 39:
slideNext();
break;
default:
break;
}
}
function testSlide() {
var now = $('#slides').children(':visible');
var duration = now.attr('duration');
timeout = setTimeout(slideNext, duration*5000);
}
function slidePrev() {
if(timeout) clearTimeout(timeout);
var now = $('#slides').children(':visible');
var last = $('#slides').children(':last');
var prev = now.prev();
prev = prev.index() == -1 ? last : prev;
now.fadeOut(100, function() {
prev.fadeIn(100, 'swing', testSlide);
});
}
function slideNext() {
if(timeout) clearTimeout(timeout);
var now = $('#slides').children(':visible');
var first = $('#slides').children(':first');
var next = now.next();
next = now.next();
next = next.index() == -1 ? first : next;
now.fadeOut(100, function() {
next.fadeIn(100, 'swing', testSlide);
});
}