-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
101 lines (82 loc) · 3.01 KB
/
Copy pathscript.js
File metadata and controls
101 lines (82 loc) · 3.01 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
let menuIcon = document.querySelector("#menu-icon");
let navbar = document.querySelector(".navbar");
let sections = document.querySelectorAll("section");
let navLinks = document.querySelectorAll("header nav a");
window.onscroll = () => {
sections.forEach(sec => {
let top = window.scrollY;
let offset = sec.offsetTop - 150;
let height = sec.offsetHeight;
let id = sec.getAttribute("id");
if (top >= offset && top < offset + height) {
navLinks.forEach(link => {
link.classList.remove("active");
});
document.querySelector(`header nav a[href="#${id}"]`).classList.add("active");
}
});
};
menuIcon.onclick = () => {
menuIcon.classList.toggle("bx-x");
navbar.classList.toggle("active");
};
menuIcon.addEventListener("mouseenter", () => {
menuIcon.classList.add("bx-x");
navbar.classList.add("active");
});
document.addEventListener("click", (event) => {
if (!navbar.contains(event.target) && event.target !== menuIcon) {
menuIcon.classList.remove("bx-x");
navbar.classList.remove("active");
}
});
document.addEventListener('DOMContentLoaded', function() {
const stars = document.querySelectorAll('.star');
stars.forEach(star => {
star.addEventListener('click', () => {
const value = parseInt(star.getAttribute('data-value'));
const parent = star.parentNode;
const siblings = parent.querySelectorAll('.star');
siblings.forEach(sibling => {
sibling.classList.remove('active');
});
for (let i = 0; i < value; i++) {
siblings[i].classList.add('active');
}
});
});
});
document.addEventListener('DOMContentLoaded', function() {
const checkbox = document.getElementById('language-toggle');
if (checkbox) {
// Verifica se está na página index-pt.html e marca o checkbox
if (window.location.pathname === '/index-pt.html') {
checkbox.checked = true;
} else {
checkbox.checked = false;
}
}
});
const checkbox = document.getElementById('language-toggle');
checkbox.addEventListener('change', function() {
const isChecked = this.checked;
const currentPath = window.location.pathname;
let targetPath = isChecked ? '/index-pt.html' : '/index.html';
// Verifica se o redirecionamento é necessário apenas se não estiver na página de destino
if ((isChecked && !currentPath.includes('/index-pt.html')) || (!isChecked && !currentPath.includes('/index.html'))) {
window.location.href = targetPath;
}
});
const themeToggle = document.getElementById('theme-toggle');
// Adiciona um ouvinte de evento para detectar mudanças no estado do switch
themeToggle.addEventListener('change', function() {
// Seleciona o elemento root do documento
const root = document.documentElement;
// Se o switch estiver marcado, adiciona a classe .light-theme ao root
if (this.checked) {
root.classList.add('light-theme');
} else {
// Se o switch não estiver marcado, remove a classe .light-theme do root
root.classList.remove('light-theme');
}
});