I was trying to create a simple progress bar. I need to get an event / perform action when the animation on the progress bar complete (100% width is filled by green color).
HTML -
<button>Go</button>
<p>Waiting</p>
<div id="bar" class="progress-bar">
<div class="progress-bar-fill"></div>
</div>
CSS -
.progress-bar {
background-color: #EEE;
height: 10px;
overflow: hidden;
width:100%;
}
.progress-bar-fill {
background-color: green;
height: 100%;
transition: width 5s ease 0s;
width: 0;
}
JS -
$("button").on("click", function () {
$("p").append(" --> Started");
$('#bar .progress-bar-fill').css('width', '100%');
$('#bar .progress-bar-fill').promise().done(function () {
$("p").append(" --> Finished");
});
});
Link - http://jsfiddle.net/v2unc/
WRT the code, the "Finished" indication should come after 5 seconds. But its coming as soon as the button is clicked.
The example in "http://api.jquery.com/promise/" works perfectly. Or am I looking at the wrong API?