class CustomNavbar extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
`;
// Set active link based on current page
this.setActiveLink();
// Add scroll effect
this.addScrollEffect();
}
setActiveLink() {
const currentPath = window.location.pathname.split('/').pop() || 'index.html';
const links = this.shadowRoot.querySelectorAll('.nav-link, .mobile-menu-link');
links.forEach(link => {
link.classList.remove('active');
const href = link.getAttribute('href');
if (href === currentPath) {
link.classList.add('active');
}
});
}
addScrollEffect() {
const nav = this.shadowRoot.querySelector('nav');
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
nav.style.boxShadow = '0 4px 6px rgba(0,0,0,0.1)';
nav.style.background = 'rgba(255, 255, 255, 0.95)';
nav.style.backdropFilter = 'blur(10px)';
} else {
nav.style.boxShadow = '0 2px 4px rgba(0,0,0,0.1)';
nav.style.background = 'white';
nav.style.backdropFilter = 'none';
}
});
}
}
// Mobile menu toggle function
window.toggleMobileMenu = function() {
const mobileMenu = document.querySelector('custom-navbar').shadowRoot.getElementById('mobileMenu');
mobileMenu.classList.toggle('active');
};
customElements.define('custom-navbar', CustomNavbar);