Correctly update medium-zoom background when switching theme (#332)
This commit is contained in:
parent
495c4aa8a0
commit
9c8bd1a945
|
|
@ -43,4 +43,3 @@ The rest of the images in this post are all zoomable, arranged into different mi
|
||||||
<img class="img-fluid rounded z-depth-1" src="{{ site.baseurl }}/assets/img/7.jpg" data-zoomable>
|
<img class="img-fluid rounded z-depth-1" src="{{ site.baseurl }}/assets/img/7.jpg" data-zoomable>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,33 +2,6 @@ $(document).ready(function() {
|
||||||
const mode_toggle = document.getElementById("light-toggle");
|
const mode_toggle = document.getElementById("light-toggle");
|
||||||
|
|
||||||
mode_toggle.addEventListener("click", function() {
|
mode_toggle.addEventListener("click", function() {
|
||||||
const temp = localStorage.getItem("theme");
|
toggleTheme(localStorage.getItem("theme"));
|
||||||
toggleTheme(temp);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let toggleTheme = (theme) => {
|
|
||||||
if (theme == "dark") {
|
|
||||||
setTheme("light");
|
|
||||||
} else {
|
|
||||||
setTheme("dark");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let setTheme = (theme) => {
|
|
||||||
trans();
|
|
||||||
if (theme) {
|
|
||||||
document.documentElement.setAttribute("data-theme", theme)
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
document.documentElement.removeAttribute("data-theme");
|
|
||||||
}
|
|
||||||
localStorage.setItem("theme", theme);
|
|
||||||
};
|
|
||||||
|
|
||||||
let trans = () => {
|
|
||||||
document.documentElement.classList.add("transition");
|
|
||||||
window.setTimeout(() => {
|
|
||||||
document.documentElement.classList.remove("transition")
|
|
||||||
}, 500)
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,42 @@
|
||||||
// Has to be in the head tag, otherwise a flicker effect will occur.
|
// Has to be in the head tag, otherwise a flicker effect will occur.
|
||||||
|
|
||||||
|
let toggleTheme = (theme) => {
|
||||||
|
if (theme == "dark") {
|
||||||
|
setTheme("light");
|
||||||
|
} else {
|
||||||
|
setTheme("dark");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let setTheme = (theme) => {
|
||||||
|
transTheme();
|
||||||
|
if (theme) {
|
||||||
|
document.documentElement.setAttribute("data-theme", theme);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.documentElement.removeAttribute("data-theme");
|
||||||
|
}
|
||||||
|
localStorage.setItem("theme", theme);
|
||||||
|
|
||||||
|
// Updates the background of medium-zoom overlay.
|
||||||
|
if (typeof medium_zoom !== 'undefined') {
|
||||||
|
medium_zoom.update({
|
||||||
|
background: getComputedStyle(document.documentElement)
|
||||||
|
.getPropertyValue('--global-bg-color') + 'ee', // + 'ee' for trasparency.
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
let transTheme = () => {
|
||||||
|
document.documentElement.classList.add("transition");
|
||||||
|
window.setTimeout(() => {
|
||||||
|
document.documentElement.classList.remove("transition");
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let initTheme = (theme) => {
|
let initTheme = (theme) => {
|
||||||
if (theme == null) {
|
if (theme == null) {
|
||||||
const userPref = window.matchMedia;
|
const userPref = window.matchMedia;
|
||||||
|
|
@ -6,12 +44,8 @@ let initTheme = (theme) => {
|
||||||
theme = 'dark';
|
theme = 'dark';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
setTheme(theme);
|
||||||
if (theme) {
|
|
||||||
document.documentElement.setAttribute('data-theme', theme)
|
|
||||||
}
|
|
||||||
|
|
||||||
localStorage.setItem("theme", theme);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
initTheme(localStorage.getItem("theme"));
|
initTheme(localStorage.getItem("theme"));
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
|
// Initialize medium zoom.
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
mediumZoom('[data-zoomable]', {
|
medium_zoom = mediumZoom('[data-zoomable]', {
|
||||||
margin: 100,
|
margin: 100,
|
||||||
background: getComputedStyle(document.documentElement)
|
background: getComputedStyle(document.documentElement)
|
||||||
.getPropertyValue('--global-bg-color') + 'ee',
|
.getPropertyValue('--global-bg-color') + 'ee', // + 'ee' for trasparency.
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue