-
Notifications
You must be signed in to change notification settings - Fork 224
/
pres.js
48 lines (41 loc) · 1.3 KB
/
pres.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
'use strict';
(function() {
var counter = 0;
var startPres = function(id) {
var node = document.getElementById(id);
node.addEventListener('click', handleStart);
};
var handleStart = function() {
showOnly(0);
document.addEventListener('keyup', advance);
}
var advance = function(e) {
if (e.keyCode === 37) {
// left arrow
counter--;
showOnly(counter);
}
else if (e.keyCode === 39) {
counter++;
showOnly(counter);
}
}
var showOnly = function(index) {
var nodes = document.getElementsByTagName('article');
for (var i = 0; i < nodes.length; i++) {
if (counter === i) {
console.log(i, nodes[i]);
var replace = 'invisible';
if (nodes[i].className.indexOf(' invisible') >= 0) {
replace = ' invisible';
}
nodes[i].className = nodes[i].className.replace(replace, '');
nodes[i].scrollIntoView();
}
else if (nodes[i].className.indexOf('invisible') < 0) {
nodes[i].className += (nodes[i].className.length) ? ' invisible' : 'invisible';
}
}
};
startPres('start');
})();