forked from vikhyatsingh123/Naruto-Shippuden
-
Notifications
You must be signed in to change notification settings - Fork 0
/
switch-toggle.js
51 lines (42 loc) · 1.45 KB
/
switch-toggle.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
49
50
/*
Add the class good/evil to make the character show when the good or evil slider is toggled. Simply leave no class to have
the card always show. This is good for morally ambiguous characters.
*/
const toggleInput = document.getElementById("toggle-input");
const toggleSlider = document.getElementById("toggle-slider");
const goodCharacters = document.getElementsByClassName("good");
const goodCharactersArray = Array.from(goodCharacters);
const evilCharacters = document.getElementsByClassName("evil");
const evilCharactersArray = Array.from(evilCharacters);
const isToggled = toggleInput.checked;
if (isToggled) {
hideCharacters(goodCharactersArray);
} else {
hideCharacters(evilCharactersArray);
}
toggleInput.addEventListener("change", () => {
toggleSlider.style.left = toggleInput.checked ? "50%" : "0";
if (!toggleInput.checked) {
showCharacters(goodCharactersArray);
hideCharacters(evilCharactersArray);
} else {
showCharacters(evilCharactersArray);
hideCharacters(goodCharactersArray);
}
});
function hideCharacters(characters) {
characters.forEach(character => {
character.classList.add("hide");
});
}
function showCharacters(characters) {
characters.forEach(character => {
character.classList.remove("hide");
});
}
evilCharactersArray.forEach(character => {
console.log(character);
})
goodCharactersArray.forEach(character => {
console.log(character);
})