-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
167 lines (143 loc) · 4.63 KB
/
Copy pathmain.js
File metadata and controls
167 lines (143 loc) · 4.63 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
// DOM Elements
const nav = document.querySelector('#header nav');
const toggle = document.querySelectorAll('nav .toggle');
const links = document.querySelectorAll('nav ul li a');
const header = document.querySelector('#header');
const backToTopButton = document.querySelector('.back-to-top');
const sections = document.querySelectorAll('main section[id]');
// Abre e fecha o menu quando clica no Hamburguer e no X
for (const element of toggle) {
element.addEventListener('click', function () {
nav.classList.toggle('show');
document.querySelector('.toggle').classList.toggle('show');
});
}
// Fecha o menu quando clica em um item
for (const link of links) {
link.addEventListener('click', function () {
nav.classList.remove('show');
document.querySelector('.toggle').classList.remove('show');
});
}
// Adiciona sombra no header quando scroll
function changeHeaderWhenScroll() {
if (window.scrollY >= 50) {
header.classList.add('scroll');
} else {
header.classList.remove('scroll');
}
}
// Back to top button
function backToTop() {
if (window.scrollY >= 300) {
backToTopButton.classList.add('show');
} else {
backToTopButton.classList.remove('show');
}
}
// Menu ativo conforme a seção visível
function activateMenuAtCurrentSection() {
const checkpoint = window.pageYOffset + (window.innerHeight / 8) * 4;
for (const section of sections) {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
const sectionId = section.getAttribute('id');
const checkpointStart = checkpoint >= sectionTop - 100;
const checkpointEnd = checkpoint <= sectionTop + sectionHeight - 100;
const menuLink = document.querySelector(`nav ul li a[href*="${sectionId}"]`);
if (checkpointStart && checkpointEnd) {
menuLink.classList.add('active');
} else {
menuLink.classList.remove('active');
}
}
}
// ScrollReveal animations
if (typeof ScrollReveal !== 'undefined') {
const scrollReveal = ScrollReveal({
origin: 'top',
distance: '30px',
duration: 700,
reset: false
});
scrollReveal.reveal(`
#home .fundo-texto,
.intro .text,
#about .image, #about .text,
.services-section .section-header, .services-section .card,
#contact .text, #contact .contact-info,
.help-section .text, .help-section .doacao,
footer .brand, footer .social
`, { interval: 100 });
}
// Event Listeners
window.addEventListener('scroll', function () {
changeHeaderWhenScroll();
backToTop();
activateMenuAtCurrentSection();
});
// Smooth scroll para links âncora
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
}
});
});
// Inicializações quando a página carrega
window.addEventListener('DOMContentLoaded', function () {
changeHeaderWhenScroll();
backToTop();
activateMenuAtCurrentSection();
// Adiciona ano atual no copyright
const yearSpan = document.querySelector('.copyright');
if (yearSpan) {
const currentYear = new Date().getFullYear();
yearSpan.textContent = `© ${currentYear} Instituição Adog`;
}
});
// Animação para botões de doação
document.querySelectorAll('.donation-link').forEach(link => {
link.addEventListener('click', function (e) {
if (this.getAttribute('href').startsWith('#')) {
e.preventDefault();
// Animação de clique
this.style.transform = 'scale(0.95)';
setTimeout(() => {
this.style.transform = '';
}, 200);
// Simula abertura de modal/aviso
const method = this.querySelector('span').textContent;
alert(`Obrigado por querer doar! O método "${method}" será implementado em breve.`);
}
});
});
// Validação simples do formulário (se adicionar formulário posteriormente)
if (document.querySelector('form')) {
document.querySelector('form').addEventListener('submit', function (e) {
e.preventDefault();
// Validação básica
const requiredFields = this.querySelectorAll('[required]');
let isValid = true;
requiredFields.forEach(field => {
if (!field.value.trim()) {
field.style.borderColor = 'red';
isValid = false;
} else {
field.style.borderColor = '';
}
});
if (isValid) {
// Simula envio
alert('Mensagem enviada com sucesso! Entraremos em contato em breve.');
this.reset();
}
});
}