-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
17 lines (14 loc) · 801 Bytes
/
Copy pathscript.js
File metadata and controls
17 lines (14 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const burger = document.querySelector('.burger');
const nav = document.querySelector('.nav-links');
burger.addEventListener('click', () => nav.classList.toggle('active'));
const toggle = document.getElementById('theme-toggle');
const root = document.documentElement;
const currentTheme = localStorage.getItem('theme') || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
root.setAttribute('data-theme', currentTheme);
toggle.textContent = currentTheme === 'dark' ? '☀️' : '🌙';
toggle.addEventListener('click', () => {
const theme = root.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
root.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
toggle.textContent = theme === 'dark' ? '☀️' : '🌙';
});