Dabelu's picture
I want to make a website to sell FPV Drones both for civilian, comercial, agricultural and military use. Make it interactive with buttons and object oriented
00c522e verified
Raw History Blame Contribute Delete
4.68 kB
class CustomHeader extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
header {
background-color: rgba(17, 24, 39, 0.9);
backdrop-filter: blur(10px);
padding: 1rem 0;
position: sticky;
top: 0;
z-index: 100;
border-bottom: 1px solid #374151;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 1rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
display: flex;
align-items: center;
text-decoration: none;
}
.logo-icon {
width: 40px;
height: 40px;
background: linear-gradient(135deg, #3b82f6, #1d4ed8);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
margin-right: 12px;
}
.logo-text {
font-size: 1.5rem;
font-weight: 700;
background: linear-gradient(90deg, #3b82f6, #60a5fa);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
nav ul {
display: flex;
list-style: none;
}
nav ul li {
margin-left: 2rem;
}
nav ul li a {
color: #d1d5db;
text-decoration: none;
font-weight: 500;
transition: color 0.3s;
display: flex;
align-items: center;
}
nav ul li a:hover {
color: #3b82f6;
}
nav ul li a i {
margin-right: 8px;
}
.mobile-menu-btn {
display: none;
background: none;
border: none;
color: #d1d5db;
font-size: 1.5rem;
cursor: pointer;
}
@media (max-width: 768px) {
.nav-menu {
position: fixed;
top: 70px;
left: -100%;
width: 100%;
height: calc(100vh - 70px);
background-color: rgba(17, 24, 39, 0.95);
flex-direction: column;
align-items: center;
padding-top: 2rem;
transition: left 0.3s ease;
}
.nav-menu.active {
left: 0;
}
nav ul {
flex-direction: column;
width: 100%;
}
nav ul li {
margin: 1rem 0;
text-align: center;
}
.mobile-menu-btn {
display: block;
}
}
</style>
<header>
<div class="container">
<a href="/" class="logo">
<div class="logo-icon">
<i data-feather="navigation" class="text-white w-5 h-5"></i>
</div>
<div class="logo-text">SkyHawk</div>
</a>
<button class="mobile-menu-btn" id="mobileMenuBtn">
<i data-feather="menu"></i>
</button>
<nav class="nav-menu" id="navMenu">
<ul>
<li><a href="/"><i data-feather="home"></i> Home</a></li>
<li><a href="#"><i data-feather="shopping-bag"></i> Products</a></li>
<li><a href="#"><i data-feather="settings"></i> Solutions</a></li>
<li><a href="#"><i data-feather="users"></i> Support</a></li>
<li><a href="#"><i data-feather="phone"></i> Contact</a></li>
</ul>
</nav>
</div>
</header>
`;
// Add event listeners after content is rendered
setTimeout(() => {
const mobileMenuBtn = this.shadowRoot.getElementById('mobileMenuBtn');
const navMenu = this.shadowRoot.getElementById('navMenu');
mobileMenuBtn.addEventListener('click', () => {
navMenu.classList.toggle('active');
const menuIcon = mobileMenuBtn.querySelector('i');
if (navMenu.classList.contains('active')) {
menuIcon.setAttribute('data-feather', 'x');
} else {
menuIcon.setAttribute('data-feather', 'menu');
}
feather.replace();
});
}, 0);
}
}
customElements.define('custom-header', CustomHeader);