progressbar-1
by PratapDessai
HTML
<!DOCTYPE html>
<html>
<head>
<title>Progress Bar</title>
<meta charset="utf-8">
<meta name="viewport" content="width:device-width, initial-scale=1">
<style>
.progress {
--scroll: 0%;
background: linear-gradient(to right, rgb(0, 143, 105) var(--scroll), transparent 0);
position: fixed;
width: 100%;
height: 5px;
top: 0px;
z-index: 100;
}
</style>
<script type="text/javascript">
document.addEventListenter("scroll", function () {
let scrollTop = document.documentElement["scrollTop"] || document.body["scrollTop"];
let scrollBottom = (document.documentElement["scrollHeight"] ||
document.body["scrollHeight"]) - document.documentElement.clientHeight;
scrollPercent = scrollTop / scrollBottom * 100 + "%";
document.getElementById("progress").style.setProperty("--scroll", scrollPercent);
},
{ passive: true }
);
</script>
</head>
<body>
<div class="progress"></div>
</body>
</html>