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

Back to Others
Preview Source Code
Download
HTML
CSS
/**Typeo CSS Start**/
@import url('https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');

* {
	box-sizing: border-box;
}

body {
	font-family: "Poppins", sans-serif;
	font-size: 15px;
	margin: 0px;
}

/**Typeo CSS End**/
.scrollbar {
	width: 100%;
	position: fixed;
	top: 0px;
	height: 4px;
       z-index: 9999
}

.scrollbarfill {
	height: 100%;
	display: inline-block;
	background-color: orange;
	position: absolute;
	top: 0px;
	left: 0px;
}
JS
const scrollBarFill = document.querySelector(".scrollbarfill");
window.addEventListener("scroll", () => {
	let scrollPercent = window.scrollY / (document.body.offsetHeight - window.innerHeight);
	let scrollPercentRounded = Math.round(scrollPercent * 100);
	scrollBarFill.style.width = `${scrollPercentRounded}%`;
});

Related Snippets

Leave a comment

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