document.addEventListener('DOMContentLoaded', function() {
// Mobile menu toggle
const mobileMenuButton = document.getElementById('mobile-menu-button');
const mobileMenu = document.createElement('div');
mobileMenu.id = 'mobile-menu';
mobileMenu.className = 'mobile-menu fixed inset-y-0 right-0 w-64 bg-white shadow-lg z-50 p-6';
mobileMenu.innerHTML = `
Menu
`;
document.body.appendChild(mobileMenu);
mobileMenuButton.addEventListener('click', function() {
mobileMenu.classList.add('active');
feather.replace();
document.getElementById('close-mobile-menu').addEventListener('click', function() {
mobileMenu.classList.remove('active');
});
});
// Close mobile menu when clicking on a link
const mobileLinks = mobileMenu.querySelectorAll('a');
mobileLinks.forEach(link => {
link.addEventListener('click', function() {
mobileMenu.classList.remove('active');
});
});
// Smooth scroll for all links with hashes
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) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
}
});
});
// Feather icons replacement
feather.replace();
// Animation on scroll
const animateOnScroll = function() {
const elements = document.querySelectorAll('.feature-card, section[id]');
elements.forEach(element => {
const elementPosition = element.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (elementPosition < windowHeight - 100) {
element.classList.add('animate-fadeIn');
}
});
};
window.addEventListener('scroll', animateOnScroll);
animateOnScroll(); // Run once on page load
});