CoolFace
Apppublic

denysovski/electron-orbitals

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
script.js72 linesDownload Raw Back to root
1// Intersection Observer for scroll animations2const observer = new IntersectionObserver((entries) => {3    entries.forEach(entry => {4        if (entry.isIntersecting) {5            entry.target.classList.add('fade-in');6        }7    });8}, {9    threshold: 0.110});11 12document.querySelectorAll('section').forEach(section => {13    observer.observe(section);14});15// Smooth scrolling for anchor links16document.querySelectorAll('a[href^="#"]').forEach(anchor => {17    anchor.addEventListener('click', function (e) {18        e.preventDefault();19        20        const targetId = this.getAttribute('href');21        if (targetId === '#') return;22        23        const targetElement = document.querySelector(targetId);24        if (targetElement) {25            window.scrollTo({26                top: targetElement.offsetTop - 80,27                behavior: 'smooth'28            });29        }30    });31});32 33// Test drive button functionality34document.querySelector('.test-drive-btn')?.addEventListener('click', () => {35    alert('Redirecting to Tesla test drive scheduling page...');36    // In a real implementation, this would redirect or open a modal37});38// Mobile menu toggle functionality39document.addEventListener('DOMContentLoaded', () => {40    const mobileMenuButton = document.getElementById('mobile-menu-button');41    const mobileMenu = document.getElementById('mobile-menu');42    43    if (mobileMenuButton && mobileMenu) {44        mobileMenuButton.addEventListener('click', () => {45            mobileMenu.classList.toggle('hidden');46        });47    }48 49    // Highlight active nav link50    const navLinks = document.querySelectorAll('.nav-links a');51    const sections = document.querySelectorAll('section');52    53    window.addEventListener('scroll', () => {54        let current = '';55        sections.forEach(section => {56            const sectionTop = section.offsetTop;57            const sectionHeight = section.clientHeight;58            if (pageYOffset >= (sectionTop - 150)) {59                current = section.getAttribute('id');60            }61        });62 63        navLinks.forEach(link => {64            link.classList.remove('active');65            const href = link.getAttribute('href');66            if (href && href.includes(current)) {67                link.classList.add('active');68            }69        });70    });71});72