Skip to content

Instantly share code, notes, and snippets.

@kmelve
Last active February 24, 2019 11:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kmelve/8474173 to your computer and use it in GitHub Desktop.
Save kmelve/8474173 to your computer and use it in GitHub Desktop.
jQuery snippet for making a progressbar for reading position in browser.
#progresswrapper {
position: fixed;
top: 0px;
height: 2px;
width: 100%;
z-index: 1000;
}
#progressbar {
top: 0;
position: fixed;
height: 2px;
width: 100%;
background: none;
}
progress:not([value]) {
display: none;
}
progress[value] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
color: #ff0000;
background-color: #34a5c8;
border: 0;
}
progress::-webkit-progress-bar { background: none; }
progress::-webkit-progress-value { background-color: #34a5c8; }
$('body').prepend('<div id="progresswrapper"><progress id="progressbar" value="0" max="100" ></progress></div>'); // Makes a CSS styleable div for the progressbar
$(window).scroll(function () {
var scvp = $(window).scrollTop(), // pixels on top hidden from view
dh = $(document).height(), // height of document window
dp = $(window).height(); // height of broswer window
scrollPercent = (scvp / (dh-dp)) * 100;
var position = scrollPercent;
$("#progressbar").attr('value', position);
});
@mjarpitanand
Copy link

what is i want to get for a scroller only for the particular width

@Antoine-lb
Copy link

Works very well on Desktop but not very well on Opera Mini / Safari iPhone :S

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment