-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgallery.js
More file actions
50 lines (39 loc) · 1.2 KB
/
Copy pathgallery.js
File metadata and controls
50 lines (39 loc) · 1.2 KB
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
let currentlySelected = 0;
const nodes = document.querySelectorAll(".gallery-image");
const nodes2 = document.querySelectorAll(".character");
const prevBtn = document.querySelector(".prev");
const nextBtn = document.querySelector(".next");
function previous() {
nextBtn.disabled = false;
nodes[currentlySelected].classList.remove("active");
nodes2[currentlySelected].classList.remove("active");
currentlySelected--;
nodes[currentlySelected].classList.add("active");
nodes2[currentlySelected].classList.add("active");
if (currentlySelected === 0) {
prevBtn.disabled = true;
}
}
function next() {
prevBtn.disabled = false;
nodes[currentlySelected].classList.remove("active");
nodes2[currentlySelected].classList.remove("active");
currentlySelected++;
nodes[currentlySelected].classList.add("active");
nodes2[currentlySelected].classList.add("active");
if (currentlySelected + 1 === nodes.length) {
nextBtn.disabled = true;
}
if (currentlySelected + 1 === nodes2.length) {
nextBtn.disabled = true;
}
}
function init() {
prevBtn.addEventListener("click", function() {
previous();
});
nextBtn.addEventListener("click", function(e) {
next();
});
}
init();