-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
86 lines (56 loc) · 2.06 KB
/
script.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Constantes das imagens
const wallpaper = document.querySelector('.wallpaper');
const capa1 = document.querySelector('.capa1');
const capa2 = document.querySelector('.capa2');
const capa3 = document.querySelector('.capa3');
// Tema inicial da página sendo o tema claro
document.body.setAttribute("data-theme", "claro")
// Criando a variável do botão (imagem)
const input = document.querySelector('.botao')
// O tema escuro troca para o claro e o claro troca para o escuro.
const temas = {
"escuro" : "claro",
"claro" : "escuro",
}
// Variável booleana
var x = Boolean()
// A troca entre os temas
if (input) {
input.addEventListener('click', event => {
event.preventDefault()
console.log("funcionando")
x = !x
//
const temaAtual = document.body.dataset.theme
document.body.setAttribute("data-theme", temas[temaAtual] || "claro")
updateWallpaper();
if(x){
input.setAttribute("src", "media/symbol-escuro.png")
capa1.setAttribute("src", "media/lis1-capa-escuro.png")
capa2.setAttribute("src", "media/lis2-capa-escuro.png")
capa3.setAttribute("src", "media/lis3-capa-escuro.png")
} else {
input.setAttribute("src", "media/symbol-claro.png")
capa1.setAttribute("src", "media/lis1-capa.jpg")
capa2.setAttribute("src", "media/lis2-capa.jpg")
capa3.setAttribute("src", "media/lis3-capa.jpeg")
}
})
}
//Atualizando o wallpaper para celular
updateWallpaper();
function updateWallpaper() {
if(window.innerWidth <= 800 && x) {
wallpaper.setAttribute("src", "media/wallpaper-celular-escuro.jpg")
}
else if(window.innerWidth <=800 && !x){
wallpaper.setAttribute("src", "media/wallpaper-celular.jpg")
}
else if(x){
wallpaper.setAttribute("src", "media/wallpaper-escuro.jpg")
}
else {
wallpaper.setAttribute("src", "media/wallpaper.jpg")
}
}
window.addEventListener("resize", updateWallpaper);