Coder Wrap provides free to use snippets Coder Wrap provides free to use snippets

Back to Others
Preview Source Code
Download
HTML
CSS
h1{
  font-size: 38px;
  text-align: center;
  padding: 30px;
}
p{
  font-size: 15px;
  line-height: 1.5em;
}
#progress{
  width: 65px;
  height: 65px;
  background-color: #c0c0ff;
  border-radius:50%;
  position: fixed;
  bottom: 20px;
  right: 10px;
  box-shadow:0 0 10px rgba(0,0,0,0.2);
  display: grid;
  place-items:center;
}
#progress-value{
  display: block;
  height: calc(100% - 10px);
  width: calc(100% - 10px);
  background-color: #fff;
  border-radius:50%;
  display: grid;
  place-items:center;
}
JS
const scrollPercentage = ()=>{
  const scrollProgress = document.getElementById("progress");
  const progressValue = document.getElementById("progress-value");
  const pos = document.documentElement.scrollTop;
  const calcHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
  const scrollValue = Math.round( pos * 100 / calcHeight);
  scrollProgress.style.background = `conic-gradient(#000 ${scrollValue}%, #c0c0ff ${scrollValue}%)`
}

window.onscroll = scrollPercentage;

Related Snippets

Leave a comment

Your email address will not be published. Required fields are marked *