brandsthatconvert's picture
I want you to build this:
c52ddda verified
Raw History Blame Contribute Delete
2.52 kB
// Main JavaScript file for global functionality
document.addEventListener('DOMContentLoaded', function() {
// Mobile menu toggle functionality will be handled by the header component
// Smooth scrolling for anchor links
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) {
const headerOffset = 80;
const elementPosition = targetElement.getBoundingClientRect().top;
const offsetPosition = elementPosition + window.pageYOffset - headerOffset;
window.scrollTo({
top: offsetPosition,
behavior: 'smooth'
});
}
});
});
// Animation on scroll
const animateOnScroll = function() {
const elements = document.querySelectorAll('.fade-in');
elements.forEach(element => {
const elementTop = element.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (elementTop < windowHeight - 100) {
element.classList.add('opacity-100', 'translate-y-0');
}
});
};
// Initialize elements with fade-in effect
document.querySelectorAll('.feature-card, .testimonial').forEach((el, index) => {
el.classList.add('fade-in', 'opacity-0', 'translate-y-6', 'transition-all', 'duration-500', 'ease-out');
el.style.transitionDelay = `${index * 100}ms`;
});
window.addEventListener('scroll', animateOnScroll);
animateOnScroll(); // Initial check
});
// Form validation for demo requests
function validateForm(form) {
const email = form.querySelector('input[type="email"]');
const name = form.querySelector('input[type="text"]');
let isValid = true;
if (!name.value.trim()) {
name.classList.add('border-red-500');
isValid = false;
} else {
name.classList.remove('border-red-500');
}
if (!email.value.trim() || !email.value.includes('@')) {
email.classList.add('border-red-500');
isValid = false;
} else {
email.classList.remove('border-red-500');
}
return isValid;
}