Muso98's picture
sen faqat frontend yaratolasanmi?
23e9d56 verified
class CustomNavbar extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
nav {
background: white;
padding: 1rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
position: sticky;
top: 0;
z-index: 100;
}
.logo {
font-weight: 800;
font-size: 1.5rem;
background: linear-gradient(90deg, #3B82F6 0%, #8B5CF6 100%);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
display: flex;
align-items: center;
gap: 0.5rem;
}
.nav-links {
display: flex;
gap: 1.5rem;
list-style: none;
margin: 0;
padding: 0;
}
.nav-links a {
color: #4B5563;
text-decoration: none;
font-weight: 500;
transition: color 0.2s;
display: flex;
align-items: center;
gap: 0.3rem;
}
.nav-links a:hover {
color: #3B82F6;
}
.mobile-menu-btn {
display: none;
background: none;
border: none;
color: #4B5563;
font-size: 1.5rem;
cursor: pointer;
}
@media (max-width: 768px) {
.mobile-menu-btn {
display: block;
}
.nav-links {
display: none;
position: absolute;
top: 100%;
left: 0;
right: 0;
background: white;
flex-direction: column;
padding: 1rem;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
}
.nav-links.show {
display: flex;
}
}
</style>
<nav>
<a href="/" class="logo">
<span>PureFront</span>
<i data-feather="zap"></i>
</a>
<button class="mobile-menu-btn">
<i data-feather="menu"></i>
</button>
<ul class="nav-links">
<li><a href="/"><i data-feather="home"></i> Home</a></li>
<li><a href="#features"><i data-feather="star"></i> Features</a></li>
<li><a href="#about"><i data-feather="info"></i> About</a></li>
<li><a href="#contact"><i data-feather="mail"></i> Contact</a></li>
</ul>
</nav>
`;
// Mobile menu toggle functionality
const mobileBtn = this.shadowRoot.querySelector('.mobile-menu-btn');
const navLinks = this.shadowRoot.querySelector('.nav-links');
mobileBtn.addEventListener('click', () => {
navLinks.classList.toggle('show');
const icon = mobileBtn.querySelector('i');
if (navLinks.classList.contains('show')) {
icon.setAttribute('data-feather', 'x');
} else {
icon.setAttribute('data-feather', 'menu');
}
feather.replace();
});
}
}
customElements.define('custom-navbar', CustomNavbar);