Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
xxEjXNX
// true が dark mode
// false が normal mode
function getMode(type) {
const $body = $('body');
// typeの引数でonとoffを判別
const check = type ? 'on' : 'off';
type ? $body.addClass('dark') : $body.addClass('light');
type ? $body.removeClass('light') : $body.removeClass('dark');
$('input[name="view-mode"]').prop('checked', type);
$.cookie(type, check, { expires: 365, path:'/'});
}
// trueでdark mode : falseでnormal modeで切替
getMode(true);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment