Skip to content

Instantly share code, notes, and snippets.

@FlowerYT6
Created February 11, 2025 09:05
Show Gist options
  • Save FlowerYT6/421d040d3154bf21da7d722af1959227 to your computer and use it in GitHub Desktop.
Save FlowerYT6/421d040d3154bf21da7d722af1959227 to your computer and use it in GitHub Desktop.
stackoverflow_solve_1
<h3>Dynamic Progress Bar</h3>
<p>Running progress bar from 0% to 100% in 10 seconds</p>
<a href="#"><button id="testButton" class="testButton">Submit</button></a> <!--new-->
<div class="progress">
<div id="dynamic" class="progress-bar progress-bar-success progress-bar-striped active" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
</div>
</div>
$(function() {
var current_progress = 0;
// new
var progress = document.getElementsByClassName("progress")[0];
var testButton = document.getElementsByClassName("testButton")[0]; //can use ids instead
// end
var interval = setInterval(function() {
current_progress += 10;
$("#dynamic")
.css("width", current_progress + "%")
.attr("aria-valuenow", current_progress)
.text(current_progress + "% Complete");
if (current_progress >= 101) {
clearInterval(interval);
progress.style.display = "none";
testButton.style.display = "block";
}
}, 1000);
});
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
/*new*/
body {
margin: 20px;
}
.progress {
width: 700px;
}
/*new*/
.testButton {
display: none; /*hide initially*/
padding: 8px 16px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment