-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
237 lines (200 loc) · 6.67 KB
/
main.js
File metadata and controls
237 lines (200 loc) · 6.67 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
235
236
237
// DOM Elements
const nav = document.querySelector('#header nav');
const toggle = document.querySelector('.toggle');
const links = document.querySelectorAll('.nav-link');
const header = document.querySelector('#header');
const backToTopButton = document.querySelector('.back-to-top');
const sections = document.querySelectorAll('main section[id]');
// Initialize Swiper
let testimonialsSwiper = null;
function initSwiper() {
if (document.querySelector('.testimonials-swiper')) {
testimonialsSwiper = new Swiper('.testimonials-swiper', {
slidesPerView: 1,
spaceBetween: 30,
loop: true,
pagination: {
el: '.swiper-pagination',
clickable: true,
},
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
breakpoints: {
768: {
slidesPerView: 2,
},
1024: {
slidesPerView: 3,
}
},
autoplay: {
delay: 5000,
disableOnInteraction: false,
},
});
}
}
// Toggle mobile menu
toggle.addEventListener('click', function () {
nav.classList.toggle('show');
toggle.classList.toggle('show');
// Toggle body scroll
document.body.style.overflow = nav.classList.contains('show') ? 'hidden' : '';
});
// Close menu when clicking on links
links.forEach(link => {
link.addEventListener('click', function() {
nav.classList.remove('show');
toggle.classList.remove('show');
document.body.style.overflow = '';
});
});
// Add shadow to header on 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');
}
}
// Active menu based on current section
function activateMenuAtCurrentSection() {
const checkpoint = window.pageYOffset + (window.innerHeight / 8) * 4;
sections.forEach(section => {
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-link[href*="${sectionId}"]`);
if(menuLink && checkpointStart && checkpointEnd) {
menuLink.classList.add('active');
} else if(menuLink) {
menuLink.classList.remove('active');
}
});
}
// ScrollReveal animations
function initScrollReveal() {
if(typeof ScrollReveal !== 'undefined') {
const scrollReveal = ScrollReveal({
origin: 'top',
distance: '30px',
duration: 700,
reset: false
});
// Home section
scrollReveal.reveal('.home-image', { delay: 200 });
scrollReveal.reveal('.home-title', { delay: 300 });
scrollReveal.reveal('.home-subtitle', { delay: 400 });
scrollReveal.reveal('.home-description', { delay: 500 });
scrollReveal.reveal('.home-features', { delay: 600 });
scrollReveal.reveal('.home-content .button', { delay: 700 });
// Categories
scrollReveal.reveal('.category-card', { interval: 100 });
// Product sections
scrollReveal.reveal('.product-image', { origin: 'left' });
scrollReveal.reveal('.product-content', { origin: 'right' });
// Services
scrollReveal.reveal('.service-card', { interval: 100 });
// Contact
scrollReveal.reveal('.contact-content', { origin: 'left' });
scrollReveal.reveal('.contact-form', { origin: 'right' });
}
}
// Contact form handler
function initContactForm() {
const contactForm = document.getElementById('contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(this);
const name = formData.get('name') || this.querySelector('input[type="text"]').value;
const phone = formData.get('phone') || this.querySelector('input[type="tel"]').value;
const message = formData.get('message') || this.querySelector('textarea').value;
// Create WhatsApp message
const whatsappMessage = `Olá! Meu nome é ${name}. Telefone: ${phone}\n\nMensagem: ${message}`;
const whatsappURL = `https://api.whatsapp.com/send?phone=+5511980244279&text=${encodeURIComponent(whatsappMessage)}`;
// Open WhatsApp
window.open(whatsappURL, '_blank');
// Reset form
this.reset();
// Show success message
alert('Redirecionando para o WhatsApp para enviar sua mensagem!');
});
}
}
// Smooth scroll for anchor links
function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
const href = this.getAttribute('href');
if (href === '#') return;
e.preventDefault();
const targetElement = document.querySelector(href);
if (targetElement) {
const headerHeight = header.offsetHeight;
const targetPosition = targetElement.offsetTop - headerHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
}
// Initialize everything when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
initSwiper();
initScrollReveal();
initContactForm();
initSmoothScroll();
// Set current year in footer
const yearSpan = document.querySelector('.footer-bottom p');
if (yearSpan) {
const currentYear = new Date().getFullYear();
yearSpan.textContent = `© ${currentYear} Vendas Baldez. Todos os direitos reservados.`;
}
});
// Scroll event listeners
window.addEventListener('scroll', function() {
changeHeaderWhenScroll();
backToTop();
activateMenuAtCurrentSection();
});
// Resize event listener
window.addEventListener('resize', function() {
// Reinitialize Swiper on resize if needed
if (testimonialsSwiper) {
testimonialsSwiper.update();
}
});
// Product category click handler
document.querySelectorAll('.category-card').forEach(card => {
card.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId && targetId.startsWith('#')) {
const targetElement = document.querySelector(targetId);
if (targetElement) {
const headerHeight = header.offsetHeight;
const targetPosition = targetElement.offsetTop - headerHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
}
});
});