Created
December 13, 2017 19:03
-
-
Save demiters/12fc208aa54e39a5e5d433f030275158 to your computer and use it in GitHub Desktop.
Simple progress bar logic with materializecss.com and jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="progress" class="progress"> | |
<div id="progressBar" class="determinate" style="width: 0%"></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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