Skip to content

Instantly share code, notes, and snippets.

@ariakm25
Last active December 21, 2019 05:21
Show Gist options
  • Save ariakm25/8bc5f3a9ce28fac7b483debc236101e3 to your computer and use it in GitHub Desktop.
Save ariakm25/8bc5f3a9ce28fac7b483debc236101e3 to your computer and use it in GitHub Desktop.
Toggle Dark Mode
// Check Dark Mode activated in Local Storage
localStorage.getItem('darkmode','dark') ? $('#darkmode').prop('checked', true) : '' ;
$('#darkmode').is(':checked') ? $('body').addClass('dark') : $('body').removeClass('dark')
$('#darkmode').on('click', function(){
$('#darkmode').is(':checked') ? $('body').addClass('dark') : $('body').removeClass('dark')
})
//Dark Mode Trigger
$('#darkmode').on('change', function() {
setInterval(() => {
this.checked ? localStorage.setItem('darkmode','dark') : localStorage.removeItem('darkmode');
}, 10);
}).trigger('change');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment