class CustomNavbar extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
`;
const mobileToggle = this.shadowRoot.querySelector('.mobile-menu-toggle');
const mobileMenu = this.shadowRoot.querySelector('.mobile-menu');
mobileToggle.addEventListener('click', () => {
mobileMenu.classList.toggle('active');
});
// Close mobile menu when clicking outside
document.addEventListener('click', (e) => {
if (!this.contains(e.target)) {
mobileMenu.classList.remove('active');
}
});
// Add scroll effect
window.addEventListener('scroll', () => {
if (window.scrollY > 50) {
this.shadowRoot.querySelector('nav').style.boxShadow = '0 4px 30px rgba(0, 0, 0, 0.1)';
} else {
this.shadowRoot.querySelector('nav').style.boxShadow = '0 2px 20px rgba(0, 0, 0, 0.1)';
}
});
}
}
customElements.define('custom-navbar', CustomNavbar);