Spaces:
Running
Running
File size: 7,902 Bytes
50653da | 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 238 239 240 241 242 243 244 245 246 247 | // Mobile menu toggle
document.addEventListener('DOMContentLoaded', function() {
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
mobileMenuBtn.addEventListener('click', function() {
mobileMenu.classList.toggle('hidden');
});
// Close mobile menu when clicking on a link
const mobileLinks = mobileMenu.querySelectorAll('a');
mobileLinks.forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.add('hidden');
});
});
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Form submission handling
document.getElementById('contact-form')?.addEventListener('submit', function(e) {
e.preventDefault();
// Add loading state
const submitBtn = this.querySelector('button[type="submit"]');
const originalText = submitBtn.textContent;
submitBtn.innerHTML = '<span class="loading"></span> Enviando...';
submitBtn.disabled = true;
// Simulate form submission
setTimeout(() => {
// Reset form
this.reset();
// Show success message
submitBtn.textContent = '✓ Enviado com sucesso!';
submitBtn.classList.add('bg-green-600', 'form-success');
submitBtn.classList.remove('bg-blue-600');
// Reset button after 3 seconds
setTimeout(() => {
submitBtn.textContent = originalText;
submitBtn.classList.remove('bg-green-600', 'form-success');
submitBtn.classList.add('bg-blue-600');
submitBtn.disabled = false;
}, 3000);
}, 2000);
});
// Parallax effect for hero section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('#home');
if (hero) {
hero.style.transform = `translateY(${scrolled * 0.5}px)`;
}
});
// Intersection Observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe all sections for animation
document.querySelectorAll('section').forEach(section => {
section.style.opacity = '0';
section.style.transform = 'translateY(20px)';
section.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(section);
});
// Dynamic particles effect
function createParticles() {
const hero = document.querySelector('#home');
if (!hero) return;
const particlesContainer = document.createElement('div');
particlesContainer.className = 'hero-particles';
for (let i = 0; i < 20; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.width = Math.random() * 50 + 20 + 'px';
particle.style.height = particle.style.width;
particle.style.left = Math.random() * 100 + '%';
particle.style.top = Math.random() * 100 + '%';
particle.style.animationDelay = Math.random() * 6 + 's';
particle.style.animationDuration = (Math.random() * 3 + 3) + 's';
particlesContainer.appendChild(particle);
}
hero.appendChild(particlesContainer);
}
// Initialize particles when page loads
window.addEventListener('load', createParticles);
// Dynamic copyright year
const currentYear = new Date().getFullYear();
const copyrightElement = document.querySelector('footer p');
if (copyrightElement) {
copyrightElement.textContent = `© ${currentYear} E-quality Lab. Todos os direitos reservados.`;
}
// Floating WhatsApp button (optional)
function createWhatsAppButton() {
const whatsappBtn = document.createElement('a');
whatsappBtn.href = 'https://wa.me/5511123456789'; // Replace with actual number
whatsappBtn.target = '_blank';
whatsappBtn.className = 'floating-btn bg-green-600 hover:bg-green-700 w-14 h-14 rounded-full flex items-center justify-center shadow-lg transition-all';
whatsappBtn.innerHTML = '<i data-feather="message-circle" class="w-7 h-7 text-white"></i>';
// Add to DOM
document.body.appendChild(whatsappBtn);
// Re-render feather icons
feather.replace();
}
// Initialize WhatsApp button (optional)
// createWhatsAppButton();
// Active navigation highlight
window.addEventListener('scroll', () => {
const sections = document.querySelectorAll('section[id]');
const scrollPosition = window.scrollY + 100;
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
const sectionId = section.getAttribute('id');
if (scrollPosition >= sectionTop && scrollPosition < sectionTop + sectionHeight) {
document.querySelectorAll('nav a').forEach(link => {
link.classList.remove('text-blue-400');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('text-blue-400');
}
});
}
});
});
// Debounce function for scroll events
function debounce(func, wait, immediate) {
let timeout;
return function executedFunction(...args) {
const later = () => {
timeout = null;
if (!immediate) func(...args);
};
const callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func(...args);
};
}
// Improve performance with debounced scroll events
const debouncedScrollHandler = debounce(() => {
// Scroll-related code here
}, 10);
window.addEventListener('scroll', debouncedScrollHandler);
// Add loading animation for images
document.querySelectorAll('img').forEach(img => {
img.addEventListener('load', function() {
this.style.opacity = '0';
this.style.transition = 'opacity 0.3s ease';
setTimeout(() => {
this.style.opacity = '1';
}, 100);
});
});
// Preload images for better performance
function preloadImages() {
const images = [
'http://static.photos/laboratory/1200x630/42',
'http://static.photos/laboratory/640x360/123',
'http://static.photos/technology/640x360/456',
'http://static.photos/science/640x480/789'
];
images.forEach(src => {
const img = new Image();
img.src = src;
});
}
// Initialize preloading
preloadImages();
// Add typing effect to hero title
function typeWriter(element, text, speed = 50) {
let i = 0;
element.textContent = '';
function type() {
if (i < text.length) {
element.textContent += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// Initialize typing effect when hero is visible
const heroTitle = document.querySelector('#home h1');
if (heroTitle) {
const originalText = heroTitle.textContent;
const heroObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
typeWriter(heroTitle, originalText, 50);
heroObserver.unobserve(entry.target);
}
});
});
heroObserver.observe(heroTitle);
} |