Navbar Glassmorphism

Démonstration de la Navbar

Code HTML

HTML
<nav class="navbar">
  <div class="nav-container">
    <div class="nav-logo">
      <a href="#">
        <i class='bx bx-code-alt'></i>
        <span>EXTRIZY</span>
      </a>
    </div>
    
    <ul class="nav-menu">
      <li class="nav-item">
        <a href="#" class="nav-link active">Accueil</a>
      </li>
      <li class="nav-item">
        <a href="#" class="nav-link">Extraits</a>
      </li>
      <li class="nav-item">
        <a href="#" class="nav-link">Catégories</a>
      </li>
      <li class="nav-item">
        <a href="#" class="nav-link">À propos</a>
      </li>
    </ul>
    
    <div class="theme-toggle">
      <button class="theme-btn">
        <i class='bx bx-moon'></i>
      </button>
    </div>
  </div>
</nav>

Code CSS

CSS
/* Navigation Glassmorphism */
.navbar {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.navbar.scrolled {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 80px;
}

.nav-logo a {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: #ffffff;
  font-size: 1.75rem;
  font-weight: 700;
  transition: all 0.3s ease;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.nav-logo i {
  font-size: 2.5rem;
  color: #ffffff;
  filter: drop-shadow(0 2px 10px rgba(0, 0, 0, 0.1));
}

.nav-menu {
  display: flex;
  list-style: none;
  gap: 40px;
  margin: 0;
  padding: 0;
}

.nav-link {
  text-decoration: none;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 500;
  font-size: 1.1rem;
  transition: all 0.3s ease;
  position: relative;
  padding: 8px 16px;
  border-radius: 20px;
}

.nav-link:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: #ffffff;
  transition: all 0.3s ease;
  transform: translateX(-50%);
  border-radius: 1px;
}

.nav-link:hover::after {
  width: 80%;
}

.nav-link.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 20px rgba(255, 255, 255, 0.2);
}

.theme-toggle {
  display: flex;
  align-items: center;
}

.theme-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  padding: 12px;
  color: #ffffff;
  cursor: pointer;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.theme-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.4);
  transform: scale(1.1) rotate(180deg);
  box-shadow: 0 8px 25px rgba(255, 255, 255, 0.2);
}

Code JavaScript

JavaScript
// Effet de scroll pour la navbar
function handleNavbarScroll() {
  const navbar = document.getElementById('main-navbar');
  
  if (window.scrollY > 50) {
    navbar.classList.add('scrolled');
  } else {
    navbar.classList.remove('scrolled');
  }
}

// Ajouter l'événement de scroll
window.addEventListener('scroll', handleNavbarScroll);

// Gestionnaire de thème
class ThemeManager {
  constructor() {
    this.currentTheme = 'dark';
    this.init();
  }

  init() {
    this.loadSavedTheme();
    this.setupThemeToggle();
  }

  setupThemeToggle() {
    const themeBtn = document.getElementById('theme-toggle-btn');
    if (themeBtn) {
      themeBtn.addEventListener('click', () => this.toggleTheme());
    }
  }

  loadSavedTheme() {
    const savedTheme = localStorage.getItem('extrizy-theme');
    if (savedTheme) {
      this.setTheme(savedTheme);
    } else {
      this.setTheme('dark');
    }
  }

  setTheme(theme) {
    this.currentTheme = theme;
    document.body.setAttribute('data-theme', theme);
    localStorage.setItem('extrizy-theme', theme);
    this.updateThemeIcons();
  }

  toggleTheme() {
    const newTheme = this.currentTheme === 'dark' ? 'light' : 'dark';
    this.setTheme(newTheme);
  }

  updateThemeIcons() {
    const sunIcon = document.getElementById('sun-icon');
    const moonIcon = document.getElementById('moon-icon');
    
    if (sunIcon && moonIcon) {
      if (this.currentTheme === 'dark') {
        sunIcon.style.display = 'none';
        moonIcon.style.display = 'block';
      } else {
        sunIcon.style.display = 'block';
        moonIcon.style.display = 'none';
      }
    }
  }
}

// Initialiser le gestionnaire de thème
document.addEventListener('DOMContentLoaded', function() {
  new ThemeManager();
});