-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
205 lines (169 loc) · 5.47 KB
/
main.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
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
function onScroll() {
showNavOnScroll();
showBackToTopButtonOnScroll();
trocarImagemComScroll();
activateMenuAtCurrentSection(home);
activateMenuAtCurrentSection(services);
activateMenuAtCurrentSection(about);
activateMenuAtCurrentSection(contact);
}
window.addEventListener("scroll", onScroll);
function activateMenuAtCurrentSection(section) {
const targetLine = scrollY + innerHeight / 2;
// verificar se a seção passou da linha
// quais dados vou precisar?
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionTopReachOrPassedTargetline = targetLine >= sectionTop;
// verificar se a base está abaixo da linha alvo
const sectionEndsAt = sectionTop + sectionHeight;
const sectionEndPassedTargetline = sectionEndsAt >= targetLine;
// limites da seção
const sectionBoundaries =
sectionTopReachOrPassedTargetline && sectionEndPassedTargetline;
const sectionId = section.getAttribute("id");
const menuElement = document.querySelector(`.menu a[href*=${sectionId}]`);
menuElement.classList.remove("active");
if (sectionBoundaries) {
menuElement.classList.add("active");
}
}
function showNavOnScroll() {
var navigation = document.getElementById("navigation");
if (navigation) {
// Verifica se o elemento foi encontrado no DOM
if (window.scrollY > 0) {
navigation.classList.add("scroll");
} else {
navigation.classList.remove("scroll");
}
}
}
// Função para trocar o src da imagem com base no scroll
function trocarImagemComScroll() {
// Condição para verificar se o scroll é maior que 0
if (window.scrollY > 0) {
// Obtém a referência da imagem pelo ID
var imagem = document.getElementById("logoImage");
// Novo caminho do arquivo src
var novoSrc = "./assets/asp-logo-branco.png";
// Troca o src da imagem
imagem.src = novoSrc;
} else {
// Obtém a referência da imagem pelo ID
var imagem = document.getElementById("logoImage");
// Novo caminho do arquivo src
var blunovoSrc = "./assets/asp-logo-azul.png";
// Troca o src da imagem
imagem.src = blunovoSrc;
}
}
/*function showNavOnScroll() {
if (scrollY > 0) {
navigation.classList.add('scroll')
} else {
navigation.classList.remove('scroll')
}
}*/
function showBackToTopButtonOnScroll() {
if (scrollY > 400) {
backToTopButton.classList.add("show");
} else {
backToTopButton.classList.remove("show");
}
}
function openMenu() {
document.body.classList.add("menu-expanded");
}
function closeMenu() {
document.body.classList.remove("menu-expanded");
}
ScrollReveal({
origin: "top",
distance: "30px",
duration: 700,
}).reveal(`
#home,
#home img,
#home .stats,
#services,
#services header,
#services .card
#about,
#about header,
#about .content`);
function openPopup() {
document.getElementById("overlay").style.display = "block";
document.getElementById("popup").style.display = "block";
document.body.classList.add("no-scroll"); // Adiciona a classe para bloquear o scroll
}
function closePopup() {
document.getElementById("overlay").style.display = "none";
document.getElementById("popup").style.display = "none";
document.body.classList.remove("no-scroll"); // Remove a classe para permitir o scroll novamente
}
// STATS DINAMICOS
// Função para animar as estatísticas
function animarEstatisticas() {
// Defina os valores iniciais e finais para cada estatística
var clientesInicial = 0;
var clientesFinal = 20000;
var especialistasInicial = 0;
var especialistasFinal = 40;
var anosInicial = 0;
var anosFinal = 30;
// Função para atualizar dinamicamente as estatísticas
function atualizarEstatisticas(
statElement,
inicial,
final,
incremento,
delay
) {
var valorAtual = inicial;
function atualizar() {
valorAtual += incremento;
// Atualiza o valor na página
statElement.querySelector("h3").textContent =
"+" + Math.round(valorAtual);
// Verifica se atingiu o valor final
if (valorAtual < final) {
// Chama a função novamente após um intervalo
setTimeout(atualizar, delay);
}
}
// Inicia a atualização
atualizar();
}
// Obtém os elementos das estatísticas
var clientesStat = document.getElementById("clientesStat");
var especialistasStat = document.getElementById("especialistasStat");
var anosStat = document.getElementById("anosStat");
// Inicia a animação das estatísticas com valores iniciais, finais, incremento e delay
atualizarEstatisticas(clientesStat, clientesInicial, clientesFinal, 100, 20); // Ajuste os valores conforme necessário
atualizarEstatisticas(
especialistasStat,
especialistasInicial,
especialistasFinal,
1,
100
); // Tempo menor para especialistasStat
atualizarEstatisticas(anosStat, anosInicial, anosFinal, 1, 90); // Tempo menor para anosStat
}
// Chama a função para iniciar a animação das estatísticas quando a página carregar
document.addEventListener("DOMContentLoaded", animarEstatisticas);
// FUNÇÃO PARA O POPUP PRINCIPAL
function openCustomPopup(popupId) {
var customPopup = document.getElementById(popupId);
if (customPopup) {
customPopup.style.display = "flex";
document.body.classList.add("no-scroll");
}
}
function closeCustomPopup(popupId) {
var customPopup = document.getElementById(popupId);
if (customPopup) {
customPopup.style.display = "none";
document.body.classList.remove("no-scroll");
}
}