mirror of
https://github.com/thecyberlearn/2026_NetcopTech.git
synced 2026-08-18 06:32:50 +00:00
74 lines
2.5 KiB
JavaScript
74 lines
2.5 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
// Mobile Menu Toggle
|
|
const mobileMenuBtn = document.querySelector('.mobile-menu-btn');
|
|
const nav = document.querySelector('.nav');
|
|
|
|
// Toggle menu
|
|
mobileMenuBtn.addEventListener('click', () => {
|
|
mobileMenuBtn.classList.toggle('active');
|
|
nav.classList.toggle('active');
|
|
document.body.classList.toggle('no-scroll');
|
|
});
|
|
|
|
// Close mobile menu when clicking a link
|
|
document.querySelectorAll('.nav a').forEach(link => {
|
|
link.addEventListener('click', () => {
|
|
mobileMenuBtn.classList.remove('active');
|
|
nav.classList.remove('active');
|
|
document.body.classList.remove('no-scroll');
|
|
});
|
|
});
|
|
|
|
// Header Scroll Effect
|
|
const header = document.querySelector('.header');
|
|
window.addEventListener('scroll', () => {
|
|
if (window.scrollY > 50) {
|
|
header.classList.add('scrolled');
|
|
} else {
|
|
header.classList.remove('scrolled');
|
|
}
|
|
});
|
|
|
|
// Smooth Scrolling for anchor links
|
|
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) {
|
|
// Adjust offset based on header height
|
|
const headerOffset = 90;
|
|
const elementPosition = targetElement.getBoundingClientRect().top;
|
|
const offsetPosition = elementPosition + window.scrollY - headerOffset;
|
|
|
|
window.scrollTo({
|
|
top: offsetPosition,
|
|
behavior: 'smooth'
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
// Intersection Observer for Fade In Animations
|
|
const observerOptions = {
|
|
root: null,
|
|
rootMargin: '0px',
|
|
threshold: 0.1
|
|
};
|
|
|
|
const observer = new IntersectionObserver((entries, observer) => {
|
|
entries.forEach(entry => {
|
|
if (entry.isIntersecting) {
|
|
entry.target.classList.add('visible');
|
|
observer.unobserve(entry.target); // Animates only once
|
|
}
|
|
});
|
|
}, observerOptions);
|
|
|
|
// Observe elements with fade-in-up class
|
|
const animatedElements = document.querySelectorAll('.fade-in-up');
|
|
animatedElements.forEach(el => observer.observe(el));
|
|
});
|