zhengr's picture
鍏徃鍚嶇О鏀逛负 MixTAO Lab
82385fc verified
class CustomNavbar extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
nav {
background: white;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
position: fixed;
width: 100%;
top: 0;
z-index: 1000;
transition: all 0.3s ease;
}
.nav-container {
max-width: 1280px;
margin: 0 auto;
padding: 0 1rem;
display: flex;
justify-content: space-between;
align-items: center;
height: 80px;
}
.logo {
display: flex;
align-items: center;
font-size: 1.5rem;
font-weight: 800;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
text-decoration: none;
transition: transform 0.3s ease;
}
.logo:hover {
transform: scale(1.05);
}
.logo-icon {
width: 40px;
height: 40px;
margin-right: 0.5rem;
}
.nav-links {
display: flex;
gap: 2rem;
align-items: center;
list-style: none;
}
.nav-link {
color: #4a5568;
text-decoration: none;
font-weight: 500;
position: relative;
transition: color 0.3s ease;
padding: 0.5rem 0;
}
.nav-link::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 0;
height: 2px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
transition: width 0.3s ease;
}
.nav-link:hover {
color: #667eea;
}
.nav-link:hover::after {
width: 100%;
}
.nav-link.active {
color: #667eea;
}
.nav-link.active::after {
width: 100%;
}
.cta-button {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 0.75rem 1.5rem;
border-radius: 50px;
text-decoration: none;
font-weight: 600;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
.cta-button:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}
.mobile-menu-toggle {
display: none;
background: none;
border: none;
cursor: pointer;
padding: 0.5rem;
}
.mobile-menu-toggle svg {
width: 24px;
height: 24px;
color: #4a5568;
}
.mobile-menu {
display: none;
position: absolute;
top: 100%;
left: 0;
right: 0;
background: white;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
padding: 1rem;
transform: translateY(-100%);
opacity: 0;
transition: all 0.3s ease;
}
.mobile-menu.active {
transform: translateY(0);
opacity: 1;
}
.mobile-menu-links {
list-style: none;
display: flex;
flex-direction: column;
gap: 1rem;
}
.mobile-menu-link {
color: #4a5568;
text-decoration: none;
font-weight: 500;
padding: 0.75rem;
border-radius: 0.5rem;
transition: all 0.3s ease;
}
.mobile-menu-link:hover {
background: #f7fafc;
color: #667eea;
}
.mobile-menu-link.active {
color: #667eea;
background: #f7fafc;
}
@media (max-width: 768px) {
.nav-links {
display: none;
}
.mobile-menu-toggle {
display: block;
}
.mobile-menu {
display: block;
}
}
</style>
<nav>
<div class="nav-container">
<a href="index.html" class="logo">
<span class="logo-icon">馃</span>
MixTAO Lab
</a>
<ul class="nav-links">
<li><a href="index.html" class="nav-link active">Home</a></li>
<li><a href="products.html" class="nav-link">Products</a></li>
<li><a href="about.html" class="nav-link">About</a></li>
<li><a href="contact.html" class="nav-link">Contact</a></li>
<li><a href="contact.html" class="cta-button">Get Started</a></li>
</ul>
<button class="mobile-menu-toggle" onclick="toggleMobileMenu()">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
</svg>
</button>
</div>
<div class="mobile-menu" id="mobileMenu">
<ul class="mobile-menu-links">
<li><a href="index.html" class="mobile-menu-link active">Home</a></li>
<li><a href="products.html" class="mobile-menu-link">Products</a></li>
<li><a href="about.html" class="mobile-menu-link">About</a></li>
<li><a href="contact.html" class="mobile-menu-link">Contact</a></li>
<li><a href="contact.html" class="mobile-menu-link" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;">Get Started</a></li>
</ul>
</div>
</nav>
`;
// 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);