Back To Top
<style>
/* The existing styles for the Back to Top button */
#progress {
position: fixed;
bottom: 30px;
right: 30px;
height: 50px;
width: 50px;
display: none;
place-items: center;
border-radius: 50%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
cursor: pointer;
}
#progress::before {
content: "↑"; /* The content of the pseudo-element, which displays the arrow symbol */
display: block;
height: calc(100% - 10px);
width: calc(100% - 10px);
background-color: #2b3546;
border-radius: 50%;
display: grid;
place-items: center;
font-size: 20px;
color: #ffffff;
}
}
</style>
<script>
let calcScrollValue = () => {
let scrollProgress = document.getElementById("progress");
let pos = document.documentElement.scrollTop;
let calcHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
let scrollValue = Math.round((pos * 100) / calcHeight);
if (pos > 100) {
scrollProgress.style.display = "grid";
} else {
scrollProgress.style.display = "none";
}
scrollProgress.addEventListener("click", () => {
smoothScrollTo(0); // Smoothly scroll to top when progress element is clicked
});
scrollProgress.style.background = `conic-gradient(#8467D9 ${scrollValue}%, #d7d7d7 ${scrollValue}%)`;
};
const smoothScrollTo = (targetPosition) => {
const startPosition = document.documentElement.scrollTop;
const distance = targetPosition - startPosition;
const duration = 800; // Time in milliseconds for smooth scroll animation
let startTime = null;
const animation = (currentTime) => {
if (!startTime) startTime = currentTime;
const timeElapsed = currentTime - startTime;
const scrollY = easeInOutQuad(timeElapsed, startPosition, distance, duration);
document.documentElement.scrollTop = scrollY;
if (timeElapsed < duration) {
requestAnimationFrame(animation);
}
};
requestAnimationFrame(animation);
};
// Easing function for smooth scroll animation
const easeInOutQuad = (t, b, c, d) => {
t /= d / 2;
if (t < 1) return (c / 2) * t * t + b;
t--;
return (-c / 2) * (t * (t - 2) - 1) + b;
};
window.onscroll = calcScrollValue;
window.onload = calcScrollValue;
</script>
<style>
#progress::before {
display: block;
height: calc(100% - 15px);
width: calc(100% - 15px);
border-radius: 50%;
display: grid;
place-items: center;
font-size: 20px;
}
</style>
<script>
// Function for the smooth scroll effect
const smoothScrollTo = (targetPosition) => {
const startPosition = document.documentElement.scrollTop;
const distance = targetPosition - startPosition;
const duration = 800; // Time in milliseconds for smooth scroll animation
let startTime = null;
const animation = (currentTime) => {
if (!startTime) startTime = currentTime;
const timeElapsed = currentTime - startTime;
const scrollY = easeInOutQuad(timeElapsed, startPosition, distance, duration);
document.documentElement.scrollTop = scrollY;
if (timeElapsed < duration) {
requestAnimationFrame(animation);
}
};
requestAnimationFrame(animation);
};
// Easing function for smooth scroll animation
const easeInOutQuad = (t, b, c, d) => {
t /= d / 2;
if (t < 1) return (c / 2) * t * t + b;
t--;
return (-c / 2) * (t * (t - 2) - 1) + b;
};
let calcScrollValue = () => {
let scrollProgress = document.getElementById("progress");
let pos = document.documentElement.scrollTop;
let calcHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
let scrollValue = Math.round((pos * 100) / calcHeight);
if (pos > 100) {
scrollProgress.style.display = "grid";
} else {
scrollProgress.style.display = "none";
}
scrollProgress.addEventListener("click", () => {
smoothScrollTo(0); // Smoothly scroll to top when progress element is clicked
});
//Change icon background color
scrollProgress.style.background = `conic-gradient(#62708a ${scrollValue}%, #2b3546 ${scrollValue}%)`;
};
window.onscroll = calcScrollValue;
window.onload = calcScrollValue;
</script>
<style>
#progress::before {
display: block;
height: calc(100% - 15px);
width: calc(100% - 15px);
border-radius: 50%;
display: grid;
place-items: center;
font-size: 20px;
</style>
<script>
let calcScrollValue = () => {
let scrollProgress = document.getElementById("progress");
let pos = document.documentElement.scrollTop;
let calcHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
let scrollValue = Math.round((pos * 100) / calcHeight);
if (pos > 100) {
scrollProgress.style.display = "grid";
} else {
scrollProgress.style.display = "none";
}
scrollProgress.addEventListener("click", () => {
smoothScrollToTop();
});
//Change icon background color
scrollProgress.style.background = `conic-gradient(#62708a ${scrollValue}%, #2b3546 ${scrollValue}%)`;
};
let smoothScrollToTop = () => {
const currentPosition = document.documentElement.scrollTop;
const targetPosition = 0;
const duration = 1000; // Time in milliseconds for smooth scroll animation
let startTime = null;
const animation = (currentTime) => {
if (startTime === null) startTime = currentTime;
const timeElapsed = currentTime - startTime;
const ease = easeInOutQuad(timeElapsed, currentPosition, targetPosition - currentPosition, duration);
document.documentElement.scrollTop = ease;
if (timeElapsed < duration) {
requestAnimationFrame(animation);
}
};
requestAnimationFrame(animation);
};
// Easing function for smooth scroll animation
const easeInOutQuad = (t, b, c, d) => {
t /= d / 2;
if (t < 1) return (c / 2) * t * t + b;
t--;
return (-c / 2) * (t * (t - 2) - 1) + b;
};
window.onscroll = calcScrollValue;
window.onload = calcScrollValue;
</script>
<style>
/* The existing styles for the Back to Top button */
#progress {
position: fixed;
bottom: 30px;
right: 30px;
height: 50px;
width: 50px;
display: none;
place-items: center;
border-radius: 30%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
cursor: pointer;
}
#progress::before {
content: "↑"; /* The content of the pseudo-element, which displays the arrow symbol */
display: block;
height: calc(100% - 10px);
width: calc(100% - 10px);
background-color: #2b3546;
border-radius: 30%;
display: grid;
place-items: center;
font-size: 20px;
color: #ffffff;
}
</style>
<script>
let calcScrollValue = () => {
let scrollProgress = document.getElementById("progress");
let pos = document.documentElement.scrollTop;
let calcHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
let scrollValue = Math.round((pos * 100) / calcHeight);
if (pos > 100) {
scrollProgress.style.display = "grid";
} else {
scrollProgress.style.display = "none";
}
scrollProgress.addEventListener("click", () => {
smoothScrollTo(0); // Smoothly scroll to top when progress element is clicked
});
scrollProgress.style.background = `conic-gradient(#8467D9 ${scrollValue}%, #d7d7d7 ${scrollValue}%)`;
};
const smoothScrollTo = (targetPosition) => {
const startPosition = document.documentElement.scrollTop;
const distance = targetPosition - startPosition;
const duration = 800; // Time in milliseconds for smooth scroll animation
let startTime = null;
const animation = (currentTime) => {
if (!startTime) startTime = currentTime;
const timeElapsed = currentTime - startTime;
const scrollY = easeInOutQuad(timeElapsed, startPosition, distance, duration);
document.documentElement.scrollTop = scrollY;
if (timeElapsed < duration) {
requestAnimationFrame(animation);
}
};
requestAnimationFrame(animation);
};
// Easing function for smooth scroll animation
const easeInOutQuad = (t, b, c, d) => {
t /= d / 2;
if (t < 1) return (c / 2) * t * t + b;
t--;
return (-c / 2) * (t * (t - 2) - 1) + b;
};
window.onscroll = calcScrollValue;
window.onload = calcScrollValue;
</script>