Because I liked the idea I've just created a Fiddle :
$(function () {
$('.knob').knob({
readOnly: false,
'width': 150,
'height': 150,
'dynamicDraw': true,
'thickness': 0.4,
'tickColorizeValues': true,
'skin': 'tron',
displayInput: true,
change: function (value) {
var tKnobsVal = 0;
$(".knob").each(function () {
tKnobsVal += parseInt($(this).val());
});
var kDiff = tKnobsVal - 100;
adjustKnob(this.$.attr("id"), kDiff);
}
});
$('#btn').click(function () {
$({
value: $('.knob').val()
}).animate({
value: 33
}, {
duration: 700,
easing: 'swing',
progress: function () {
$('.knob').val(Math.round(this.value)).trigger('change');
}
});
});
});
function adjustKnob(id, value) {
var cValue = value / 2;
$(".knob").not("[id=" + id + "]").each(function () {
changeKnob($(this).attr("id"), cValue);
});
}
function changeKnob(id, value) {
$({
value: $("#" + id).val()
}).animate({
value: $("#" + id).val() - value
}, {
duration: 700,
easing: 'swing',
progress: function () {
$("#" + id).val(Math.round(this.value)).trigger('change');
}
});
}
On the knob change
event, the sum of all knob values is retrieved:
var tKnobsVal = 0;
$(".knob").each(function () {
tKnobsVal += parseInt($(this).val());
});
Then the function adjustKnob()
is called with the value var kDiff = tKnobsVal - 100;
(for the difference from 100) and the id of the knob that has been changed.
adjustKnob()
then calls changeKnob()
for every knob except the knob that was changed with half of kDiff
.
In the Fiddle I added a button to set and reset all 3 knobs to the initial 33. Note that there is some finetuning missing (sometimes the sum of all knobs will equal a little bit above or less 100) but that's maybe caused e.g. by the sum of all knobs not having 100 as initial value because of the missing 1%.