| |
| document.addEventListener('DOMContentLoaded', function() { |
| |
| const navLinks = document.querySelectorAll('.nav-link'); |
| |
| navLinks.forEach(link => { |
| link.addEventListener('click', function(e) { |
| e.preventDefault(); |
| const targetId = this.getAttribute('href'); |
| const targetSection = document.querySelector(targetId); |
| |
| if (targetSection) { |
| const offsetTop = targetSection.offsetTop - 60; |
| window.scrollTo({ |
| top: offsetTop, |
| behavior: 'smooth' |
| }); |
| |
| |
| const navMenu = document.querySelector('.nav-menu'); |
| const hamburger = document.querySelector('.hamburger'); |
| navMenu.classList.remove('active'); |
| hamburger.classList.remove('active'); |
| } |
| }); |
| }); |
| |
| |
| const hamburger = document.querySelector('.hamburger'); |
| const navMenu = document.querySelector('.nav-menu'); |
| |
| hamburger.addEventListener('click', function() { |
| navMenu.classList.toggle('active'); |
| this.classList.toggle('active'); |
| }); |
| |
| |
| document.addEventListener('click', function(e) { |
| if (!hamburger.contains(e.target) && !navMenu.contains(e.target)) { |
| navMenu.classList.remove('active'); |
| hamburger.classList.remove('active'); |
| } |
| }); |
| |
| |
| const navbar = document.querySelector('.navbar'); |
| let lastScrollY = window.scrollY; |
| |
| window.addEventListener('scroll', function() { |
| if (window.scrollY > 100) { |
| navbar.style.background = 'rgba(255, 255, 255, 0.95)'; |
| } else { |
| navbar.style.background = 'rgba(255, 255, 255, 0.8)'; |
| } |
| |
| |
| if (window.scrollY > lastScrollY && window.scrollY > 200) { |
| navbar.style.transform = 'translateY(-100%)'; |
| } else { |
| navbar.style.transform = 'translateY(0)'; |
| } |
| |
| lastScrollY = window.scrollY; |
| }); |
| |
| |
| const lazyImages = document.querySelectorAll('img[loading="lazy"]'); |
| |
| if ('IntersectionObserver' in window) { |
| const imageObserver = new IntersectionObserver((entries, observer) => { |
| entries.forEach(entry => { |
| if (entry.isIntersecting) { |
| const img = entry.target; |
| img.src = img.src; |
| imageObserver.unobserve(img); |
| } |
| }); |
| }); |
| |
| lazyImages.forEach(img => imageObserver.observe(img)); |
| } |
| |
| |
| const observerOptions = { |
| threshold: 0.1, |
| rootMargin: '0px 0px -50px 0px' |
| }; |
| |
| const observer = new IntersectionObserver(function(entries) { |
| entries.forEach(entry => { |
| if (entry.isIntersecting) { |
| entry.target.style.opacity = '1'; |
| entry.target.style.transform = 'translateY(0)'; |
| } |
| }); |
| }, observerOptions); |
| |
| |
| const sections = document.querySelectorAll('.section'); |
| sections.forEach(section => { |
| section.style.opacity = '0'; |
| section.style.transform = 'translateY(20px)'; |
| section.style.transition = 'opacity 0.6s ease, transform 0.6s ease'; |
| observer.observe(section); |
| }); |
| }); |