|
1 | 1 | // Theme Toggle Logic |
2 | 2 | const themeToggle = document.getElementById('theme-toggle'); |
| 3 | +const hamburger = document.getElementById('hamburger'); |
| 4 | +const navMenu = document.getElementById('nav-menu'); |
3 | 5 | const body = document.body; |
4 | | -const icon = themeToggle.querySelector('i'); |
| 6 | +const themeIcon = themeToggle.querySelector('i'); |
| 7 | +const menuIcon = hamburger.querySelector('i'); |
5 | 8 |
|
6 | | -// Check for saved theme |
| 9 | +// Theme Logic |
7 | 10 | const savedTheme = localStorage.getItem('theme'); |
8 | 11 | if (savedTheme === 'dark') { |
9 | 12 | body.classList.add('dark-mode'); |
10 | | - icon.classList.replace('fa-moon', 'fa-sun'); |
| 13 | + themeIcon.classList.replace('fa-moon', 'fa-sun'); |
11 | 14 | } |
12 | 15 |
|
13 | 16 | themeToggle.addEventListener('click', () => { |
14 | 17 | body.classList.toggle('dark-mode'); |
15 | | - |
16 | 18 | if (body.classList.contains('dark-mode')) { |
17 | 19 | localStorage.setItem('theme', 'dark'); |
18 | | - icon.classList.replace('fa-moon', 'fa-sun'); |
| 20 | + themeIcon.classList.replace('fa-moon', 'fa-sun'); |
19 | 21 | } else { |
20 | 22 | localStorage.setItem('theme', 'light'); |
21 | | - icon.classList.replace('fa-sun', 'fa-moon'); |
| 23 | + themeIcon.classList.replace('fa-sun', 'fa-moon'); |
22 | 24 | } |
23 | 25 | }); |
24 | 26 |
|
| 27 | +// Hamburger Menu Logic |
| 28 | +hamburger.addEventListener('click', () => { |
| 29 | + navMenu.classList.toggle('active'); |
| 30 | + menuIcon.classList.toggle('fa-bars'); |
| 31 | + menuIcon.classList.toggle('fa-times'); |
| 32 | +}); |
| 33 | + |
| 34 | +// Close menu when clicking links |
| 35 | +document.querySelectorAll('.nav-menu a').forEach(link => { |
| 36 | + link.addEventListener('click', () => { |
| 37 | + navMenu.classList.remove('active'); |
| 38 | + menuIcon.classList.replace('fa-times', 'fa-bars'); |
| 39 | + }); |
| 40 | +}); |
| 41 | + |
25 | 42 | // Scroll Reveal Animation |
26 | 43 | const revealElements = document.querySelectorAll('[data-reveal]'); |
27 | 44 |
|
|
0 commit comments