-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
234 lines (175 loc) · 6.93 KB
/
Copy pathscript.js
File metadata and controls
234 lines (175 loc) · 6.93 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*==================================================
PORTFÓLIO DANIEL LIMA - JS FINAL
====================================================*/
document.addEventListener("DOMContentLoaded", () => {
/* MENU MOBILE */
const menuToggle = document.querySelector(".menu-toggle");
const menu = document.querySelector(".menu");
if (menuToggle && menu) {
menuToggle.addEventListener("click", () => {
menu.classList.toggle("active");
const icon = menuToggle.querySelector("i");
if (icon) {
icon.classList.toggle("fa-bars");
icon.classList.toggle("fa-xmark");
}
});
}
/* SCROLL SUAVE */
const linksMenu = document.querySelectorAll('a[href^="#"]');
linksMenu.forEach(link => {
link.addEventListener("click", function (e) {
const href = this.getAttribute("href");
if (!href || href === "#") return;
const destino = document.querySelector(href);
if (destino) {
e.preventDefault();
destino.scrollIntoView({
behavior: "smooth",
block: "start"
});
if (menu) {
menu.classList.remove("active");
}
if (menuToggle) {
const icon = menuToggle.querySelector("i");
if (icon) {
icon.classList.add("fa-bars");
icon.classList.remove("fa-xmark");
}
}
}
});
});
/* NAVBAR AO ROLAR */
const navbar = document.querySelector(".navbar");
if (navbar) {
window.addEventListener("scroll", () => {
if (window.scrollY > 80) {
navbar.style.background = "rgba(7, 13, 24, .92)";
navbar.style.boxShadow = "0 20px 60px rgba(0,0,0,.45)";
navbar.style.borderColor = "rgba(56,189,248,.28)";
} else {
navbar.style.background = "rgba(7, 13, 24, .78)";
navbar.style.boxShadow = "0 20px 60px rgba(0,0,0,.30)";
navbar.style.borderColor = "rgba(148,163,184,.18)";
}
});
}
/* EFEITO DIGITAÇÃO */
const textoDigitado = "Analista de Business Intelligence";
const subtitulo = document.querySelector(".hero h2");
if (subtitulo) {
let i = 0;
subtitulo.textContent = "";
function escrever() {
if (i < textoDigitado.length) {
subtitulo.textContent += textoDigitado.charAt(i);
i++;
setTimeout(escrever, 65);
}
}
escrever();
}
/* CONTADORES */
const counters = document.querySelectorAll(".stat h3");
if (counters.length > 0) {
const counterObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const counter = entry.target;
const original = counter.innerText;
const numero = parseInt(original.replace(/\D/g, ""));
if (isNaN(numero)) return;
const possuiK = original.toLowerCase().includes("k");
const possuiMais = original.includes("+");
let atual = 0;
const incremento = Math.max(1, numero / 70);
function contar() {
atual += incremento;
if (atual < numero) {
if (possuiK && possuiMais) {
counter.innerText = Math.floor(atual) + "k+";
} else if (possuiK) {
counter.innerText = Math.floor(atual) + "k";
} else if (possuiMais) {
counter.innerText = Math.floor(atual) + "+";
} else {
counter.innerText = Math.floor(atual);
}
requestAnimationFrame(contar);
} else {
counter.innerText = original;
}
}
contar();
counterObserver.unobserve(counter);
}
});
}, {
threshold: 0.45
});
counters.forEach(counter => counterObserver.observe(counter));
}
/* REVEAL AO ROLAR */
const reveals = document.querySelectorAll(".reveal");
if (reveals.length > 0) {
const revealObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add("active");
}
});
}, {
threshold: 0.12,
rootMargin: "0px 0px -40px 0px"
});
reveals.forEach(item => revealObserver.observe(item));
}
/* FORMULÁRIO */
const formulario = document.querySelector("form");
const botaoEnviar = formulario ? formulario.querySelector("button") : null;
if (formulario && botaoEnviar) {
const textoOriginal = botaoEnviar.innerHTML;
formulario.addEventListener("submit", () => {
botaoEnviar.innerHTML = `<i class="fa-solid fa-spinner fa-spin"></i> Enviando...`;
botaoEnviar.disabled = true;
setTimeout(() => {
botaoEnviar.innerHTML = textoOriginal;
botaoEnviar.disabled = false;
}, 6000);
});
}
/* ANO AUTOMÁTICO */
const anoAtual = new Date().getFullYear();
const footerTexto = document.querySelector("footer p:last-child");
if (footerTexto) {
footerTexto.innerHTML = `© ${anoAtual} Daniel Lima. Todos os direitos reservados.`;
}
/* WHATSAPP COM MENSAGEM PRONTA */
const whatsappFloat = document.querySelector(".whatsapp-float");
if (whatsappFloat) {
const mensagem = encodeURIComponent(
"Olá, Daniel! Vi seu portfólio e gostaria de conversar sobre dados/BI."
);
whatsappFloat.href = `https://wa.me/5585994012461?text=${mensagem}`;
}
/* MENU ATIVO AO ROLAR */
const sections = document.querySelectorAll("section[id], header[id]");
const navLinks = document.querySelectorAll(".menu a");
window.addEventListener("scroll", () => {
let current = "";
sections.forEach(section => {
const sectionTop = section.offsetTop - 180;
if (window.scrollY >= sectionTop) {
current = section.getAttribute("id");
}
});
navLinks.forEach(link => {
link.classList.remove("active");
if (link.getAttribute("href") === `#${current}`) {
link.classList.add("active");
}
});
});
});