undefined / script.js
avgads's picture
inserir rodapé
41e4d5d verified
Raw History Blame Contribute Delete
5.41 kB
// Shared JavaScript across all pages
document.addEventListener('DOMContentLoaded', function() {
// Initialize feather icons
feather.replace();
// Smooth scroll 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'
});
}
});
});
// Add animation on scroll
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-fade-in');
}
});
}, observerOptions);
// Observe all sections
document.querySelectorAll('section').forEach(section => {
observer.observe(section);
});
// Countdown timer for limited offer
function startCountdown() {
const countdownElement = document.getElementById('countdown');
if (!countdownElement) return;
let timeLeft = 3600; // 1 hour in seconds
const timer = setInterval(function() {
const hours = Math.floor(timeLeft / 3600);
const minutes = Math.floor((timeLeft % 3600) / 60);
const seconds = timeLeft % 60;
countdownElement.textContent = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
if (timeLeft <= 0) {
clearInterval(timer);
countdownElement.textContent = "EXPIRED";
}
timeLeft--;
}, 1000);
}
// Start countdown if element exists
startCountdown();
// Form validation
const forms = document.querySelectorAll('form');
forms.forEach(form => {
form.addEventListener('submit', function(e) {
e.preventDefault();
// Simple validation
const emailInput = form.querySelector('input[type="email"]');
if (emailInput && !emailInput.value.match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)) {
emailInput.classList.add('border-red-500');
return;
}
// Show success message
const successMessage = document.createElement('div');
successMessage.className = 'bg-green-100 text-green-700 p-4 rounded-lg mt-4';
successMessage.textContent = 'Thank you for your submission!';
form.appendChild(successMessage);
// Reset form
form.reset();
// Remove message after 5 seconds
setTimeout(() => {
successMessage.remove();
}, 5000);
});
});
// Sticky header effect
let lastScroll = 0;
window.addEventListener('scroll', function() {
const navbar = document.querySelector('nav');
if (!navbar) return;
const currentScroll = window.pageYOffset;
if (currentScroll > 100) {
navbar.classList.add('shadow-lg');
} else {
navbar.classList.remove('shadow-lg');
}
lastScroll = currentScroll;
});
// Mobile menu toggle
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.getElementById('mobile-menu');
if (mobileMenuButton && mobileMenu) {
mobileMenuButton.addEventListener('click', function() {
mobileMenu.classList.toggle('hidden');
});
}
// Lazy loading for images
const images = document.querySelectorAll('img[data-src]');
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);
}
});
});
images.forEach(img => imageObserver.observe(img));
// Tooltip functionality
const tooltips = document.querySelectorAll('[data-tooltip]');
tooltips.forEach(element => {
element.addEventListener('mouseenter', function() {
const tooltip = document.createElement('div');
tooltip.className = 'absolute bg-gray-800 text-white text-sm px-2 py-1 rounded z-50';
tooltip.textContent = this.dataset.tooltip;
tooltip.style.top = '-30px';
tooltip.style.left = '50%';
tooltip.style.transform = 'translateX(-50%)';
this.style.position = 'relative';
this.appendChild(tooltip);
});
element.addEventListener('mouseleave', function() {
const tooltip = this.querySelector('.absolute');
if (tooltip) {
tooltip.remove();
}
});
});
});
console.log('Uroflow website loaded successfully');