-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinder.js
More file actions
38 lines (31 loc) · 864 Bytes
/
binder.js
File metadata and controls
38 lines (31 loc) · 864 Bytes
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
const spreads = document.querySelectorAll(".spread");
const prevBtn = document.querySelector(".controls button:nth-child(1)");
const nextBtn = document.querySelector(".controls button:nth-child(2)");
let current = 0;
function update() {
spreads.forEach((spread, i) => {
spread.classList.toggle("active", i === current);
});
// Hide / disable buttons at bounds
prevBtn.classList.toggle("hidden", current === 0);
nextBtn.classList.toggle("hidden", current === spreads.length - 1);
}
function next() {
if (current < spreads.length - 1) {
current++;
update();
}
}
function prev() {
if (current > 0) {
current--;
update();
}
}
/* Keyboard navigation */
document.addEventListener("keydown", e => {
if (e.key === "ArrowRight") next();
if (e.key === "ArrowLeft") prev();
});
/* Initialize correct button state */
update();