-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (45 loc) · 1.82 KB
/
script.js
File metadata and controls
52 lines (45 loc) · 1.82 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
// Seleciona o botão e a seção "sobre"
const btnTopo = document.getElementById('btnTopo');
const sectionSobre = document.getElementById('sobre');
// Função para verificar a visibilidade da seção
window.addEventListener('scroll', () => {
// Pega a distância do topo da página até o topo da seção
const distanciaTopo = sectionSobre.offsetTop;
// Pega a posição atual do scroll
const scrollAtual = window.scrollY;
// Altura da janela do navegador
const alturaTela = window.innerHeight;
// Quando a rolagem chegar próximo da seção "sobre"
if (scrollAtual + alturaTela / 2 >= distanciaTopo) {
btnTopo.classList.add('mostrar'); // Mostra o botão
} else {
btnTopo.classList.remove('mostrar'); // Esconde o botão
}
});
// Animação suave para voltar ao topo
btnTopo.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
// Formulario
const form = document.getElementById('formContato');
const inputs = form.querySelectorAll('input, textarea');
const botao = document.getElementById('btnEnviar');
const mensagemSucesso = document.getElementById('mensagemSucesso');
// Habilita o botão apenas quando todos os campos estiverem válidos
form.addEventListener('input', () => {
const todosPreenchidos = Array.from(inputs).every(input => input.checkValidity());
botao.disabled = !todosPreenchidos;
});
// "Simulação" que enviou
form.addEventListener('submit', (e) => {
e.preventDefault(); // impede o envio real
botao.disabled = true;
botao.textContent = "Enviando...";
// Simula um pequeno tempo de processamento
setTimeout(() => {
mensagemSucesso.style.display = "block";
botao.textContent = "Enviar";
form.reset();
botao.disabled = true; // desativa novamente até preencher tudo
}, 1500);
});