My-website/public/scripts/theme-toggle.js
2026-01-15 12:44:10 -07:00

13 lines
No EOL
573 B
JavaScript
Executable file

const colorPicker = document.getElementById('theme-color-picker'); // Get the color picker element
// set intial color
const currentColor = localStorage.getItem('theme-color'); || '#3f10ad';
document.documentElement.style.setProperty('--primary-color', currentColor);
colorPicker.value = currentColor;
// update theme color and sae in local storage
colorPicker.addEventListener('input', (event) => {
const newColor = event.target.value;
document.documentElement.style.setProperty('--primary-color', newColor);
localStorage.setItem('theme-color', newColor);
})