|
document.addEventListener('DOMContentLoaded', function () { |
|
const navbar = document.querySelector('.header'); |
|
|
|
|
|
window.addEventListener('scroll', function() { |
|
if (window.scrollY > 0) { |
|
navbar.classList.add('scrolled'); |
|
} else { |
|
navbar.classList.remove('scrolled'); |
|
} |
|
}); |
|
|
|
const sections = document.querySelectorAll('.section'); |
|
let currentIndex = 0; |
|
const totalSections = sections.length; |
|
|
|
|
|
function scrollToSection(index) { |
|
if (index < 0 || index >= totalSections) return; |
|
const section = sections[index]; |
|
window.scrollTo({ |
|
top: section.offsetTop, |
|
behavior: 'smooth', |
|
}); |
|
} |
|
|
|
|
|
let isScrolling = false; |
|
window.addEventListener('wheel', function (e) { |
|
if (isScrolling) return; |
|
|
|
isScrolling = true; |
|
|
|
if (e.deltaY > 0 && currentIndex < totalSections - 1) { |
|
currentIndex++; |
|
} else if (e.deltaY < 0 && currentIndex > 0) { |
|
currentIndex--; |
|
} |
|
|
|
|
|
scrollToSection(currentIndex); |
|
|
|
|
|
setTimeout(() => { |
|
isScrolling = false; |
|
}, 1000); |
|
}); |
|
|
|
|
|
function animateSections() { |
|
sections.forEach((section) => { |
|
|
|
const sectionPosition = section.getBoundingClientRect(); |
|
if (sectionPosition.top < window.innerHeight && sectionPosition.bottom >= 0) { |
|
section.classList.add('visible'); |
|
} |
|
}); |
|
} |
|
|
|
|
|
animateSections(); |
|
|
|
|
|
window.addEventListener('scroll', animateSections); |
|
|
|
|
|
document.querySelectorAll('.navigation ul li a').forEach(anchor => { |
|
anchor.addEventListener('click', function(e) { |
|
e.preventDefault(); |
|
|
|
|
|
const targetId = this.getAttribute('href').substring(1); |
|
|
|
|
|
const targetSection = document.getElementById(targetId); |
|
|
|
|
|
targetSection.scrollIntoView({ |
|
behavior: 'smooth', |
|
block: 'start' |
|
}); |
|
}); |
|
}); |
|
}); |