Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Created February 27, 2020 16:12
Show Gist options
  • Save ChrisLTD/fb5869f95c2e9e3176390a8ce460aa6d to your computer and use it in GitHub Desktop.
Save ChrisLTD/fb5869f95c2e9e3176390a8ce460aa6d to your computer and use it in GitHub Desktop.
HTML / JS / SCSS progress bar
<progress value="0"></progress>
<style>
progress { width: 100%; height: 5px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: none;
background-color: white;
color: @green;
z-index: 100;
display: block;
margin: 0;
position: absolute;
top: 60px;
left: 0;
}
progress::-webkit-progress-bar {
background-color: transparent;
}
progress::-webkit-progress-value {
background-color: @green;
}
progress::-moz-progress-bar {
background-color: @green;
}
</style>
<script>
$(document).on('ready', function() {
var winHeight = $(window).height(),
docHeight = $(document).height(),
progressBar = $('progress'),
max, value;
if (progressBar.length < 1) { return; }
/* Set the max scrollable area */
max = docHeight - winHeight;
progressBar.attr('max', max);
$(document).on('scroll', function(){
value = $(window).scrollTop();
progressBar.attr('value', value);
});
$(window).on('resize', function() {
winHeight = $(window).height(),
docHeight = $(document).height();
max = docHeight - winHeight;
progressBar.attr('max', max);
value = $(window).scrollTop();
progressBar.attr('value', value);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment