Skip to content

Instantly share code, notes, and snippets.

@demiters
Created December 13, 2017 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save demiters/12fc208aa54e39a5e5d433f030275158 to your computer and use it in GitHub Desktop.
Save demiters/12fc208aa54e39a5e5d433f030275158 to your computer and use it in GitHub Desktop.
Simple progress bar logic with materializecss.com and jQuery
<div id="progress" class="progress">
<div id="progressBar" class="determinate" style="width: 0%"></div>
</div>
const progress = {
init: function(steps) {
this.step = 100 / (steps);
this.status = 0;
this.advance();
},
advance: function() {
this.status += this.step;
console.log(`Progress: ${this.status.toFixed(2)}%`);
$('#progressBar').css('width', this.status + '%');
if (this.status > 99) {
$('#progress').addClass('hide');
}
}
};
// Use with total amount of steps, initialization included
progress.init(3);
// do stuff
progress.advance();
// do stuff
progress.advance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment