-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (38 loc) · 1.47 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
49
50
51
// var icons = document.getElementsByClassName("toggle");
// var icon = icons[0];
// var elements = document.getElementsByTagName("form");
var elements = document.getElementsByClassName("toggle");
$(".toggle").click(toggleFunction());
function toggleFunction() {
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
element.onclick = function() {
document.body.classList.toggle("dark-theme");
var audio = new Audio();
// audio.src = "click.mp3";
if (document.body.classList.contains("mainToggle")) {
audio.src = "click.mp3";
} else {
audio.src = "../click.mp3";
}
audio.play();
if (document.body.classList.contains("dark-theme")) {
element.innerHTML = "Too Dark? <i class='far fa-sun'></i>";
} else {
element.innerHTML = "Too Bright? <i class='far fa-moon'></i>";
}
}
}
}
// var icon = document.getElementsByClassName("mainToggle");
// icon[0].onclick = function() {
// document.body.classList.toggle("dark-theme");
// var audio = new Audio();
// audio.src = "click.mp3";
// audio.play();
// if (document.body.classList.contains("dark-theme")) {
// icon.innerHTML = "Too Dark? <i class='far fa-sun'></i>";
// } else {
// icon.innerHTML = "Too Bright? <i class='far fa-moon'></i>";
// }
// }