Reputation: 8487
I am trying to use jquery ui progress bar with valum file upload plugin. Code :
<div id="pb"></div>
.....
onProgress: function (id, fileName, uploadedBytes, totalBytes) {
$("#pb").progressbar({ value : uploadedBytes });
},
. .... .
But this is not working, can anybody pls guid me, how to use progress bar properly ?
Upvotes: 1
Views: 9782
Reputation: 1337
Assuming you have an html with a <div id="progressbar"></div>
the following code will step through the progressbar once every 10 miliseconds untill it reaches 100:
<script type="text/javascript">
var i = 0; //variable used to count the steps
function myclick(){ // function called on a button click for example
var int = self.setInterval(
function(){
if (i == 100) window.clearInterval(int);
$( "#progressbar" ).progressbar("value", i);
i++;
}
, 10);
}
$('button').button().click(myclick); // a button element which will
// start the progress bar
$( "#progressbar" ).progressbar(); //this part sets up the progressbar
</script>
Note: The other answers are also valid, I only posted this answer as an answer to "How to properly use a progressbar" part of the question which IMO has not been answered.
Upvotes: 2
Reputation: 5238
You need to calculate the amount of uploaded bytes in percent.
var percentValue = (uploadedBytes / totalBytes) * 100
$("#pb").progressbar({
value: percentValue
});
Upvotes: 2
Reputation: 14620
The progress bar works in percentages. You will need to convert uploadedBtyes
to a % of the totalBytes
and then pass this as a number to the value property of the options.
Upvotes: 1