hugo-theme-hello-friend/source/js/theme.js

12 lines
408 B
JavaScript
Raw Normal View History

2018-07-20 19:14:22 +02:00
// Toggle theme
const getTheme = localStorage.getItem('theme')
const themeToggle = document.querySelector('.theme-toggle')
const isDark = getTheme === 'dark'
document.body.classList.toggle('dark-theme', isDark)
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('dark-theme')
localStorage.setItem('theme', document.body.classList.contains('dark-theme') ? 'dark' : 'light')
})