Nico85525's picture
ameliore ce site
947dfa4 verified
Raw History Blame Contribute Delete
3.45 kB
class CustomHeader extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
}
header {
background: rgba(15, 23, 42, 0.8);
backdrop-filter: blur(10px);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
position: sticky;
top: 0;
z-index: 50;
}
.nav-container {
max-width: 1280px;
margin: 0 auto;
padding: 0 1rem;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 0;
}
.logo {
display: flex;
align-items: center;
font-weight: 700;
font-size: 1.5rem;
color: #fff;
text-decoration: none;
}
.logo-icon {
margin-right: 0.5rem;
color: #8b5cf6;
}
.nav-links {
display: flex;
gap: 2rem;
}
.nav-link {
color: #cbd5e1;
text-decoration: none;
font-weight: 500;
transition: color 0.2s;
}
.nav-link:hover {
color: #8b5cf6;
}
.mobile-menu-btn {
display: none;
background: none;
border: none;
color: white;
font-size: 1.5rem;
cursor: pointer;
}
@media (max-width: 768px) {
.nav-links {
display: none;
position: absolute;
top: 100%;
left: 0;
right: 0;
background: rgba(15, 23, 42, 0.95);
flex-direction: column;
padding: 1rem;
gap: 1rem;
}
.nav-links.active {
display: flex;
}
.mobile-menu-btn {
display: block;
}
}
</style>
<header>
<div class="nav-container">
<nav>
<a href="/" class="logo">
<i data-feather="star" class="logo-icon"></i>
<span>Cosmic Explorer</span>
</a>
<div class="nav-links" id="navLinks">
<a href="#" class="nav-link">Gallery</a>
<a href="#" class="nav-link">Planets</a>
<a href="#" class="nav-link">Missions</a>
<a href="#" class="nav-link">About</a>
</div>
<button class="mobile-menu-btn" id="menuBtn">
<i data-feather="menu"></i>
</button>
</nav>
</div>
</header>
`;
// Initialize feather icons
feather.replace();
// Mobile menu toggle
const menuBtn = this.shadowRoot.getElementById('menuBtn');
const navLinks = this.shadowRoot.getElementById('navLinks');
menuBtn.addEventListener('click', () => {
navLinks.classList.toggle('active');
const menuIcon = menuBtn.querySelector('i');
if (navLinks.classList.contains('active')) {
menuIcon.setAttribute('data-feather', 'x');
} else {
menuIcon.setAttribute('data-feather', 'menu');
}
feather.replace();
});
}
}
customElements.define('custom-header', CustomHeader);