darkmode auto, light, dark
This commit is contained in:
@@ -86,5 +86,28 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button class="p-2 px-3" onclick="topFunction()" id="topScroll">
|
||||
<i class="fas fa-angle-up"></i>
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<script>
|
||||
var topScroll = document.getElementById("topScroll");
|
||||
window.onscroll = function() {scrollFunction()};
|
||||
|
||||
console.log(topScroll);
|
||||
function scrollFunction() {
|
||||
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
|
||||
topScroll.style.display = "block";
|
||||
} else {
|
||||
topScroll.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
function topFunction() {
|
||||
document.body.scrollTop = 0;
|
||||
document.documentElement.scrollTop = 0;
|
||||
}
|
||||
</script>
|
||||
|
||||
{{ end }}
|
||||
@@ -1,3 +1,34 @@
|
||||
{{- if (eq .Site.Params.theme.defaultTheme "light") }}
|
||||
<script>
|
||||
if (document.body.className.includes("dark")) {
|
||||
document.body.classList.remove('dark');
|
||||
localStorage.setItem("pref-theme", 'light');
|
||||
}
|
||||
</script>
|
||||
|
||||
{{ else if (eq .Site.Params.theme.defaultTheme "dark") }}
|
||||
{{- /* theme is dark */}}
|
||||
<script>
|
||||
if (document.body.className.includes("light")) {
|
||||
document.body.classList.add('dark');
|
||||
localStorage.setItem("pref-theme", 'dark');
|
||||
}
|
||||
</script>
|
||||
|
||||
{{- else }}
|
||||
{{- /* theme is auto */}}
|
||||
<script>
|
||||
if (localStorage.getItem("pref-theme") === "dark") {
|
||||
document.body.classList.add('dark');
|
||||
} else if (localStorage.getItem("pref-theme") === "light") {
|
||||
document.body.classList.remove('dark')
|
||||
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
document.body.classList.add('dark');
|
||||
}
|
||||
|
||||
</script>
|
||||
{{- end }}
|
||||
|
||||
{{- if (not .Site.Params.theme.disableThemeToggle) }}
|
||||
<script>
|
||||
document.getElementById("theme-toggle").addEventListener("click", () => {
|
||||
|
||||
Reference in New Issue
Block a user