Add static/js/back_to_top.js

This commit is contained in:
Blackwhitebear8 2025-08-13 16:03:21 +02:00
parent a3de0df91b
commit 6830f65ba3

30
static/js/back_to_top.js Normal file
View file

@ -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);