Version 1 (not so reliable, see @flup's comments)
some things to think through
you want your progress to take 10 minutes which is 600 seconds or 600.000 milliseconds.
1000 * 60 * 10 = 600.000
when your bar width is 400px (100%) you can at most do 400 steps (there isnt a smaller unit than 1px)
so if i divide 600.000ms / 400 steps, i get 1500ms, which means i should add every 1.5s one pixel. which sounds quite good.
600.000 / 400 = 1500
that would result in a code like this:
var progress = setInterval(function () {
var $bar = $('.bar');
if ($bar.width() >= 400) {
clearInterval(progress);
$('.progress').removeClass('active');
} else {
$bar.width($bar.width() + 1); // add only 1px per step
}
$bar.text($bar.width() / 4 + "%");
}, 1500); // wait 1500ms per step
EDIT
Version 2
result of the discussion (thanks @flup) is the probably most reliable version (if you want to reach the 10 mins as accurate as possible):
var mins = 10; //change this to increase or decrease minutes
var tenMinsInMillis = 1000 * 60 * mins;
var finishedTS = (new Date()).getTime() + tenMinsInMillis;
var $bar = $('.bar');
var progressInterval = 1000;
var now, remaining, pWidth;
var setBar = function (pWidth) {
$bar.width(pWidth + '%');
$bar.text(Math.floor(pWidth) + "%");
};
var progress = setInterval(function () {
now = (new Date()).getTime();
remaining = finishedTS - now;
pWidth = 100 - (remaining * 100 / tenMinsInMillis);
setBar(pWidth);
if (remaining < progressInterval) {
clearInterval(progress);
setTimeout(function () {
setBar(100);
$('.progress').removeClass('active');
}, remaining);
}
}, progressInterval);
http://jsfiddle.net/jLu8S/1/
(note, that i set the duration (var mins) to 1 minute, that you don't have to wait 10 mins in the fiddle...)