✏️ 正在编辑: script.js
路径:
/var/www/fidelizedigital.com.br/assets/js/script.js
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
// Smooth scrolling para links de navegação document.addEventListener('DOMContentLoaded', function() { // Smooth scrolling para links internos const links = document.querySelectorAll('a[href^="#"]'); links.forEach(link => { link.addEventListener('click', function(e) { e.preventDefault(); const targetId = this.getAttribute('href'); const targetSection = document.querySelector(targetId); if (targetSection) { const headerHeight = document.querySelector('.header').offsetHeight; const targetPosition = targetSection.offsetTop - headerHeight - 20; window.scrollTo({ top: targetPosition, behavior: 'smooth' }); } }); }); // FAQ Accordion const faqItems = document.querySelectorAll('.faq-item'); faqItems.forEach(item => { const question = item.querySelector('.faq-question'); question.addEventListener('click', function() { const isActive = item.classList.contains('active'); // Fechar todos os outros itens faqItems.forEach(otherItem => { if (otherItem !== item) { otherItem.classList.remove('active'); } }); // Toggle do item atual if (isActive) { item.classList.remove('active'); } else { item.classList.add('active'); } }); }); // Mobile menu toggle const navToggle = document.querySelector('.nav-toggle'); const navMenu = document.querySelector('.nav-menu'); if (navToggle && navMenu) { navToggle.addEventListener('click', function() { navMenu.classList.toggle('active'); navToggle.classList.toggle('active'); }); // Fechar menu ao clicar em um link const navLinks = document.querySelectorAll('.nav-link'); navLinks.forEach(link => { link.addEventListener('click', function() { navMenu.classList.remove('active'); navToggle.classList.remove('active'); }); }); } // Scroll to top on page load window.scrollTo(0, 0); // Header background on scroll const header = document.querySelector('.header'); window.addEventListener('scroll', function() { if (window.scrollY > 100) { header.classList.add('scrolled'); } else { header.classList.remove('scrolled'); } }); // Form validation const form = document.querySelector('.form'); if (form) { form.addEventListener('submit', function(e) { const name = document.getElementById('name').value.trim(); const email = document.getElementById('email').value.trim(); const whatsapp = document.getElementById('whatsapp').value.trim(); if (!name || !email || !whatsapp) { e.preventDefault(); alert('Por favor, preencha todos os campos obrigatórios.'); return false; } // Validação básica de email const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (!emailRegex.test(email)) { e.preventDefault(); alert('Por favor, insira um e-mail válido.'); return false; } // Validação básica de telefone const phoneRegex = /^[\d\s\(\)\-\+]+$/; if (!phoneRegex.test(whatsapp)) { e.preventDefault(); alert('Por favor, insira um número de WhatsApp válido.'); return false; } }); } // Animações de entrada const observerOptions = { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }; const observer = new IntersectionObserver(function(entries) { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate-in'); } }); }, observerOptions); // Observar elementos para animação const animateElements = document.querySelectorAll('.benefit-card, .score-card, .calc-card, .faq-item'); animateElements.forEach(el => { observer.observe(el); }); // Máscara para telefone const phoneInput = document.getElementById('whatsapp'); if (phoneInput) { phoneInput.addEventListener('input', function(e) { let value = e.target.value.replace(/\D/g, ''); if (value.length >= 11) { value = value.replace(/(\d{2})(\d{5})(\d{4})/, '($1) $2-$3'); } else if (value.length >= 7) { value = value.replace(/(\d{2})(\d{4})(\d{0,4})/, '($1) $2-$3'); } else if (value.length >= 3) { value = value.replace(/(\d{2})(\d{0,5})/, '($1) $2'); } e.target.value = value; }); } // Scroll reveal animation function revealOnScroll() { const reveals = document.querySelectorAll('.section'); reveals.forEach(reveal => { const windowHeight = window.innerHeight; const elementTop = reveal.getBoundingClientRect().top; const elementVisible = 150; if (elementTop < windowHeight - elementVisible) { reveal.classList.add('active'); } }); } window.addEventListener('scroll', revealOnScroll); revealOnScroll(); // Executar uma vez no carregamento }); // Função para scroll suave para seções específicas function scrollToSection(sectionId) { const section = document.getElementById(sectionId); if (section) { const headerHeight = document.querySelector('.header').offsetHeight; const targetPosition = section.offsetTop - headerHeight - 20; window.scrollTo({ top: targetPosition, behavior: 'smooth' }); } } // Função para abrir WhatsApp function openWhatsApp() { const message = encodeURIComponent('Olá! Gostaria de saber mais sobre o Fidelize+.'); window.open(`https://wa.me/558335070700?text=${message}`, '_blank'); } // Adicionar event listener para o botão do WhatsApp document.addEventListener('DOMContentLoaded', function() { const whatsappBtn = document.querySelector('.whatsapp-btn'); if (whatsappBtn) { whatsappBtn.addEventListener('click', function(e) { e.preventDefault(); openWhatsApp(); }); } }); // Preloader (opcional) window.addEventListener('load', function() { document.body.classList.add('loaded'); }); // Lazy loading para imagens (se houver mais imagens) if ('IntersectionObserver' in window) { const imageObserver = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { const img = entry.target; img.src = img.dataset.src; img.classList.remove('lazy'); imageObserver.unobserve(img); } }); }); const lazyImages = document.querySelectorAll('img[data-src]'); lazyImages.forEach(img => imageObserver.observe(img)); }
💾 保存文件
← 返回文件管理器