<?php $themeClass = ''; if (!empty($_COOKIE['theme'])) { if ($_COOKIE['theme'] == 'dark') { $themeClass = 'dark-theme'; } else if ($_COOKIE['theme'] == 'light') { $themeClass = 'light-theme'; } } ?>
위 소스코드를 head.php 에 넣어주시고
<body class="<?php echo $themeClass; ?>">
테마의 head.php 나 head.sub.php 에 body 태그를 찾아서 class 에 넣어주세요.
원하는 다크모드 on off 하는 버튼 넣어주세요.
<script> const btn = document.querySelector(".btn-toggle"); const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)"); btn.addEventListener("click", function() { if (prefersDarkScheme.matches) { document.body.classList.toggle("light-mode"); var theme = document.body.classList.contains("light-mode") ? "light" : "dark"; } else { document.body.classList.toggle("dark-mode"); var theme = document.body.classList.contains("dark-mode") ? "dark" : "light"; } document.cookie = "theme=" + theme; }); </script>
css 에서 light 나 dark 속성을 이용해서 만드시면 됩니다..
ex)
.light button { .... }
.light .calendar { ... }
댓글 4개
게시글 목록
| 번호 | 제목 |
|---|---|
| 23798 | |
| 23797 | |
| 23792 | |
| 23791 | |
| 23785 | |
| 23781 | |
| 23770 | |
| 23766 | |
| 23764 | |
| 23761 | |
| 23747 | |
| 23732 | |
| 23724 | |
| 23718 | |
| 23706 | |
| 23700 | |
| 23697 | |
| 23686 | |
| 23682 | |
| 23681 | |
| 23680 | |
| 23678 | |
| 23665 | |
| 23644 | |
| 23643 | |
| 23639 | |
| 23637 | |
| 23630 | |
| 23626 | |
| 23616 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기