feat: add js to check height and decide if to top is required

This commit is contained in:
Wen Junhua
2024-02-06 23:16:47 +08:00
parent 94feae3cca
commit 62d4d4112c
2 changed files with 29 additions and 12 deletions
+15
View File
@@ -38,7 +38,22 @@ if (document.documentElement.getAttribute("data-auto-appearance") === "true") {
});
}
function add_to_top_elem() {
var body = document.body,
html = document.documentElement;
const height = Math.max(
body.scrollHeight,
body.offsetHeight,
html.clientHeight,
html.scrollHeight,
html.offsetHeight
) - 150;
document.getElementById("to-top").hidden = height < window.innerHeight;
}
window.addEventListener("DOMContentLoaded", (event) => {
add_to_top_elem();
var switchers = document.querySelectorAll("[id^='appearance-switcher']");
switchers.forEach((switcher) => {
switcher.addEventListener("click", () => {