var i; // Define a global counter
var tmr; // Define timer
// Create Function
function create() {
var max = parseInt($("input#max").val(), 10),
val = parseInt($("input#val").val(), 10),
seg = parseInt($("input#seg").val(), 10),
width = parseInt($("input#width").val(), 10),
height = parseInt($("input#height").val(), 10);
$(".progressContainer").empty().height(height + 1).width(width + 1);
// Get size for each progressbar
var size = max / seg;
// Get width for each progressbar
// -2 for left/right borders of progressbars
// -1 for margin-right
// = -3px each of their width to fit exact location
width = (width / seg) - 3;
for (i = 0; i < seg; i++) {
// Create segmented progressbars
$(".progressContainer").append(
'<div class="progress' + i + '"></div>');
// Add their size
$(".progress" + i).progressbar({
max: size,
value: 0
}).css({
margin: '0 1px 0 0',
width: width,
height: height,
float: 'left'
});
}
// Get initial value
var init = val;
if (init < size) {
// if smaller than size
// than only 1 bar gonna get filled
$(".progress0").progressbar({ value: init });
} else if (init > size) {
// else calgulate how many bars
// gonna be effected
var bars = Math.floor(init / size);
for (i = 0; i < bars; i++) {
init = Math.abs(init - size);
$(".progress" + i).progressbar({ value: size });
}
// fill the value left to the last bar
$(".progress" + i).progressbar({ value: init });
}
// Now get the hell out of here!
}
function inc() {
// Define required values
var max = parseInt($("input#max").val(), 10),
seg = parseInt($("input#seg").val(), 10),
val = parseInt($("input#val").val(), 10);
// Get size for each progressbar
var size = max / seg;
// Get initial value
var init = val;
var next = val + 1;
// If progress is at max then reset it
if (init >= max) {
init = 0;
next = 0;
for...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.