From 6830f65ba3e7b9b1732279584eab21ed32243201 Mon Sep 17 00:00:00 2001 From: Blackwhitebear8 Date: Wed, 13 Aug 2025 16:03:21 +0200 Subject: [PATCH] Add static/js/back_to_top.js --- static/js/back_to_top.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 static/js/back_to_top.js diff --git a/static/js/back_to_top.js b/static/js/back_to_top.js new file mode 100644 index 0000000..f503498 --- /dev/null +++ b/static/js/back_to_top.js @@ -0,0 +1,30 @@ +const progressElement = document.getElementById("progress"); +const progressValueElement = document.getElementById("progress-value"); + +const calcScrollValue = () => { + const scrollPosition = document.documentElement.scrollTop; + const totalHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight; + + if (totalHeight > 0) { + const scrollPercent = Math.round((scrollPosition * 100) / totalHeight); + + if (scrollPosition > 100) { + progressElement.classList.add("active"); + } else { + progressElement.classList.remove("active"); + } + + progressElement.style.background = `conic-gradient(#0d6efd ${scrollPercent}%, #e6e6e6 ${scrollPercent}%)`; + } +}; + +progressElement.addEventListener("click", () => { + window.scrollTo({ + top: 0, + behavior: "smooth", + }); +}); + +window.addEventListener("scroll", calcScrollValue); + +window.addEventListener("load", calcScrollValue); \ No newline at end of file