1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-06-29 23:45:58 -04:00

add nice and soothing fade transition when dark/light mode is toggled

This commit is contained in:
2021-09-22 12:27:59 -04:00
parent 2ca02c81fd
commit 7353f0b95e
8 changed files with 64 additions and 13 deletions
+17 -2
View File
@@ -1,9 +1,24 @@
import { init } from "dark-mode-switcheroo";
import { init as darkModeInit } from "dark-mode-switcheroo";
init({
// HACK: disable theme transition until user's preference is auto-restored (1/2)
const disableTransitionCSSHack = document.createElement("style");
disableTransitionCSSHack.innerHTML = `
*,
::before,
::after {
transition-property: none !important;
}`;
document.head.appendChild(disableTransitionCSSHack);
darkModeInit({
toggle: document.querySelector(".dark-mode-toggle"),
onInit: function (t) {
// make toggle visible now that we know JS is enabled
t.style.display = "block";
// HACK: re-enable theme transitions after a very short delay, otherwise there's a weird race condition (2/2)
setTimeout(() => {
document.head.removeChild(disableTransitionCSSHack);
}, 250);
},
});