JSFiddle - React, Tailwind, and code Playground
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/ui-lightness/jquery-ui.css">
<ul id="sliders">
<li>
Adult:
<div id="adult" class="slider"></div>
<span class="value">1</span>
</li>
<li>
Child:
<div class="slider"></div>
<span class="value">0</span>
</li>
<li>
Infant
<div class="slider"></div>
<span class="value">0</span>
</li>
</ul>
CSS
#sliders {
width: 200px;
}
#sliders li {
margin-bottom: 10px;
}
#sliders div {
margin-bottom: 5px;
}
JavaScript
var sliders = $("#sliders .slider"),
smax = 400,
smin = 0;
sliders.each(function() {
var value = parseInt($(this).text(), 10),
availableTotal = smax;
$(this).empty().slider({
value: 0,
min: (this.id === 'adult') ? 1 : smin,
max: smax,
range: 'min',
step: 1,
slide: function(event, ui) {
// Update display to current value
$(this).siblings().text(ui.value);
// Get current total
var total = 0;
sliders.not(this).each(function() {
total += $(this).slider("option", "value");
});
// Need to do this because apparently jQ UI
// does not update value until this event completes
total += ui.value;
var max = availableTotal - total;
// Update each slider
sliders.not(this).each(function() {
var t = $(this),
value = t.slider("option", "value");
t.slider("option", "max", max + value)
.siblings().text(value + '/' + (max + value));
t.slider('value', value);
});
}
});
});