// Main JavaScript for HexaHost.de (function() { 'use strict'; // DOM Elements const navToggle = document.querySelector('.nav-toggle'); const navMenu = document.querySelector('.nav-menu'); const navLinks = document.querySelectorAll('.nav-link'); const glassCards = document.querySelectorAll('.glass-card'); const productCards = document.querySelectorAll('.product-card'); // Mobile Navigation Toggle if (navToggle && navMenu) { navToggle.addEventListener('click', function() { navMenu.classList.toggle('active'); navToggle.classList.toggle('active'); }); // Close mobile menu when clicking on a link navLinks.forEach(link => { link.addEventListener('click', function() { navMenu.classList.remove('active'); navToggle.classList.remove('active'); }); }); } // 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' }); } }); }); // Enhanced glass card hover effects glassCards.forEach(card => { card.addEventListener('mouseenter', function() { this.style.transform = 'translateY(-8px) scale(1.02)'; }); card.addEventListener('mouseleave', function() { this.style.transform = 'translateY(0) scale(1)'; }); }); // Product card interactive effects productCards.forEach(card => { card.addEventListener('mouseenter', function() { if (!this.classList.contains('featured')) { this.style.transform = 'translateY(-10px) scale(1.03)'; } }); card.addEventListener('mouseleave', function() { if (!this.classList.contains('featured')) { this.style.transform = 'translateY(0) scale(1)'; } }); }); // Intersection Observer for animations 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); // Observe elements for animation const animateElements = document.querySelectorAll('.glass-card, .feature-item, .product-card'); animateElements.forEach(el => { observer.observe(el); }); // Header scroll effect - always visible with transparency change const header = document.querySelector('.header'); window.addEventListener('scroll', function() { const scrollTop = window.pageYOffset || document.documentElement.scrollTop; if (scrollTop > 50) { // Scrolled down - make header more opaque header.classList.add('scrolled'); } else { // At top - make header more transparent header.classList.remove('scrolled'); } }); // Add parallax effect to hero section const hero = document.querySelector('.hero'); if (hero) { window.addEventListener('scroll', function() { const scrolled = window.pageYOffset; const rate = scrolled * -0.5; hero.style.transform = `translateY(${rate}px)`; }); } // Form validation (for contact forms) const forms = document.querySelectorAll('form'); forms.forEach(form => { form.addEventListener('submit', function(e) { const requiredFields = form.querySelectorAll('[required]'); let isValid = true; requiredFields.forEach(field => { if (!field.value.trim()) { isValid = false; field.classList.add('error'); // Remove error class on focus field.addEventListener('focus', function() { this.classList.remove('error'); }, { once: true }); } }); if (!isValid) { e.preventDefault(); showNotification('Bitte füllen Sie alle Pflichtfelder aus.', 'error'); } }); }); // Notification system function showNotification(message, type = 'info') { const notification = document.createElement('div'); notification.className = `notification notification-${type}`; notification.textContent = message; notification.style.position = 'fixed'; notification.style.top = '20px'; notification.style.right = '20px'; notification.style.padding = '15px 20px'; notification.style.borderRadius = '8px'; notification.style.color = 'white'; notification.style.fontWeight = '500'; notification.style.zIndex = '9999'; notification.style.transform = 'translateX(400px)'; notification.style.transition = 'transform 0.3s ease-in-out'; if (type === 'error') { notification.style.background = 'linear-gradient(135deg, #ef4444, #dc2626)'; } else if (type === 'success') { notification.style.background = 'linear-gradient(135deg, #10b981, #059669)'; } else { notification.style.background = 'linear-gradient(135deg, #3b82f6, #2563eb)'; } document.body.appendChild(notification); // Animate in setTimeout(() => { notification.style.transform = 'translateX(0)'; }, 100); // Remove after 5 seconds setTimeout(() => { notification.style.transform = 'translateX(400px)'; setTimeout(() => { if (notification.parentNode) { notification.parentNode.removeChild(notification); } }, 300); }, 5000); } // 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)); // Performance optimization: Debounce scroll events function debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; } // Apply debounce to scroll events const debouncedScrollHandler = debounce(function() { // Any scroll-based animations or calculations updateScrollProgress(); }, 16); // ~60fps window.addEventListener('scroll', debouncedScrollHandler); // Scroll progress indicator function updateScrollProgress() { const scrollTop = window.pageYOffset; const docHeight = document.body.scrollHeight - window.innerHeight; const scrollPercent = (scrollTop / docHeight) * 100; // You can use this to show a progress bar document.documentElement.style.setProperty('--scroll-progress', scrollPercent + '%'); } // Dark mode toggle (future feature) function initDarkMode() { const darkModeToggle = document.querySelector('.dark-mode-toggle'); if (darkModeToggle) { darkModeToggle.addEventListener('click', function() { document.body.classList.toggle('dark-mode'); localStorage.setItem('darkMode', document.body.classList.contains('dark-mode')); }); // Check for saved dark mode preference if (localStorage.getItem('darkMode') === 'true') { document.body.classList.add('dark-mode'); } } } // Initialize all features when DOM is loaded document.addEventListener('DOMContentLoaded', function() { initDarkMode(); // Add loading animation complete class document.body.classList.add('loaded'); // Show welcome message on first visit if (!localStorage.getItem('hasVisited')) { setTimeout(() => { showNotification('Willkommen bei HexaHost.de! 🚀', 'success'); localStorage.setItem('hasVisited', 'true'); }, 1000); } }); // Export functions for global access if needed window.HexaHost = { showNotification: showNotification }; })();