-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
23 lines (21 loc) · 736 Bytes
/
script.js
File metadata and controls
23 lines (21 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function toggleMode() {
const html = document.documentElement;
html.classList.toggle("light"); // forma automática
// if(html.classList.contains('light')){
// html.classList.remove('light');
// } else {
// html.classList.add('light');
// } outra forma
// pegar a tag img
const img = document.querySelector("#profile img");
// substituir a imagem
if (html.classList.contains("light")) {
// se tiver light mode adicionar a imagem light
img.setAttribute("src", "assets/avatar-light.jfif");
img.setAttribute("alt", "avatar tema light");
} else {
// se tiver sem light mode, manter a imagem normal
img.setAttribute("src", "assets/avatar.jfif");
img.setAttribute("alt", "avatar");
}
}