File size: 4,988 Bytes
2f9a6bd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | class CustomNavbar extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
width: 100%;
position: sticky;
top: 0;
z-index: 50;
background-color: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(8px);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
nav {
max-width: 1200px;
margin: 0 auto;
padding: 1rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-size: 1.25rem;
font-weight: 700;
color: #0ea5e9;
text-decoration: none;
display: flex;
align-items: center;
gap: 0.5rem;
}
.nav-links {
display: flex;
gap: 1.5rem;
}
.nav-link {
color: #334155;
text-decoration: none;
font-weight: 500;
transition: color 0.2s;
position: relative;
}
.nav-link:hover {
color: #0ea5e9;
}
.nav-link:after {
content: '';
position: absolute;
bottom: -2px;
left: 0;
width: 0;
height: 2px;
background-color: #0ea5e9;
transition: width 0.2s;
}
.nav-link:hover:after {
width: 100%;
}
.mobile-menu-btn {
display: none;
background: none;
border: none;
cursor: pointer;
}
@media (max-width: 768px) {
.mobile-menu-btn {
display: block;
}
.nav-links {
display: none;
position: absolute;
top: 100%;
left: 0;
right: 0;
background-color: white;
flex-direction: column;
padding: 1rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.nav-links.active {
display: flex;
}
}
</style>
<nav>
<a href="/" class="logo">
<span>CodeCanvas</span>
</a>
<button class="mobile-menu-btn">
<i data-feather="menu"></i>
</button>
<div class="nav-links">
<a href="#projects" class="nav-link">Projects</a>
<a href="#writing" class="nav-link">Writing</a>
<a href="#contact" class="nav-link">Contact</a>
</div>
</nav>
`;
// Initialize Feather icons
const featherScript = document.createElement('script');
featherScript.src = 'https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js';
this.shadowRoot.appendChild(featherScript);
featherScript.onload = () => {
if (window.feather) {
window.feather.replace();
}
// Mobile menu toggle
const mobileMenuBtn = this.shadowRoot.querySelector('.mobile-menu-btn');
const navLinks = this.shadowRoot.querySelector('.nav-links');
if (mobileMenuBtn && navLinks) {
mobileMenuBtn.addEventListener('click', () => {
navLinks.classList.toggle('active');
const icon = mobileMenuBtn.querySelector('i');
if (navLinks.classList.contains('active')) {
icon.setAttribute('data-feather', 'x');
} else {
icon.setAttribute('data-feather', 'menu');
}
window.feather.replace();
});
}
};
}
}
customElements.define('custom-navbar', CustomNavbar); |