Last active
December 21, 2019 05:21
-
-
Save ariakm25/8bc5f3a9ce28fac7b483debc236101e3 to your computer and use it in GitHub Desktop.
Toggle Dark Mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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