Spaces:
Running

dark-nexus-vortex / script.js
Expuz's picture
perbaiki code
7d8d684 verified
Raw History Blame Contribute Delete
2.42 kB
document.addEventListener('DOMContentLoaded', function() {
// Initialize mobile menu
initMobileMenu();
// Initialize smooth scrolling
initSmoothScrolling();
// Initialize intersection observer for animations
initIntersectionObserver();
// Re-render feather icons after dynamic content loads
setTimeout(feather.replace, 300);
});
function initMobileMenu() {
const mobileMenuBtn = document.querySelector('custom-navbar')?.shadowRoot.querySelector('.mobile-menu-btn');
const navLinks = document.querySelector('custom-navbar')?.shadowRoot.querySelector('.nav-links');
if (mobileMenuBtn && navLinks) {
mobileMenuBtn.addEventListener('click', function() {
const isOpen = navLinks.style.display === 'flex';
navLinks.style.display = isOpen ? 'none' : 'flex';
const icon = mobileMenuBtn.querySelector('i');
if (icon) {
icon.setAttribute('data-feather', isOpen ? 'menu' : 'x');
feather.replace();
}
});
}
}
function initSmoothScrolling() {
document.querySelectorAll('a[href^="#"]').forEach(function(anchor) {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth'
});
// Update URL without triggering page reload
history.pushState(null, null, targetId);
}
});
});
function initIntersectionObserver() {
const sections = document.querySelectorAll('section');
const observer = new IntersectionObserver(function(entries) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in');
}
});
}, {
threshold: 0.1
});
sections.forEach(section => {
section.classList.add('opacity-0');
observer.observe(section);
});
}, {
threshold: 0.1
});
sections.forEach(function(section) {
section.classList.add('opacity-0');
observer.observe(section);
});
}