jQuery Linked UI Sliders

A jQuery plugin that links several jQuery UI Sliders so that they always total to a given value. If you find this plugin useful please vote for it on the jQuery site.

The current version is 1.0.0, works with jQuery UI Slider version 1.8.6, and is available under the GPL and MIT licences. For more detail see the documentation reference page. Or see a minimal page that you could use as a basis for your own investigations.

Default Settings

The linked sliders functionality can easily be added to an existing set of jQuery UI Sliders with appropriate default settings.

You can also remove the linked sliders functionality if it is no longer required.

Default percentage:

 

 

   

 

$('span.defaultSlider').slider().linkedSliders().
	filter(':first').slider('value', 100);

$('#removeLinked').toggle(function() {
		$(this).text('Re-attach');
		$('span.defaultSlider').linkedSliders('destroy');
	},
	function() {
		$(this).text('Remove');
		$('span.defaultSlider').linkedSliders();
	}
);

You can override the defaults globally as shown below:

$.linkedSliders.setDefaults({policy: 'first'});

Processed elements are marked with a class of hasLinkedSliders and are not re-processed if targetted a second time.

Adjustment Policy

You can alter the order in which the other sliders are changed to retain the new total by setting the policy option.

Adjustment policy:

 

 

 

$('span.policySlider').slider().linkedSliders().
	filter(':first').slider('value', 100);

$('#policySelect').change(function() {
	$('span.policySlider').linkedSliders('change', 'policy', $(this).val());
});

Other options

The sliders may be aligned vertically.

Vertical sliders:

$('span.verticalSlider').slider({orientation: 'vertical'}).linkedSliders().
	filter(':first').slider('value', 100);

You can change the value of the sliders and linked total.

Change totals:

$('span.totalsSlider').slider({orientation: 'vertical', max: 50}).
	linkedSliders({total: 60}).
	eq(1).slider('value', 30);

In the Wild

This tab highlights examples of this plugin in use "in the wild".

To add another example, please contact me (kbwood{at}iinet.com.au) and provide the plugin name, the URL of your site, its title, and a short description of its purpose and where/how the plugin is used.

Quick Reference

A full list of all possible settings is shown below. Note that not all would apply in all cases. For more detail see the documentation reference page.

$(selector).linkedSliders({
	total: 100,  // The total for all the linked sliders
	policy: 'next' // Adjustment policy: 'next', 'prev', 'first', 'last', 'all'
});

$.linkedSliders.setDefaults(settings);  // Change default settings

$(selector).linkedSliders('change', settings);  // Update the linked settings
$(selector).linkedSliders('change', name, value);  // Update a single linked setting

$(selector).linkedSliders('destroy');  // Remove the linked sliders

Usage

  1. Include the jQuery and jQuery UI libraries in the head section of your page.
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.3/themes/south-street/ui.all.css" type="text/css">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"></script>
  2. Download and include the jQuery UI Linked Sliders JavaScript in the head section of your page.
    <script type="text/javascript" src="js/jquery.linkedsliders.js"></script>
    Alternately, you can use the packed version jquery.linkedsliders.pack.js (2.4K vs 6.0K), or the minified version jquery.linkedsliders.min.js (2.6K, 1.1K when zipped).
  3. Create your sliders and then link them together as a group.
    $('div.sliders').slider().linkedSliders();

For more detail see the documentation reference page. Or see a minimal page that you could use as a basis for your own investigations.

Comments

None as yet.

Contact Keith Wood at kbwood{at}iinet.com.au with comments or suggestions.

Change History

VersionDateChanges
1.0.029 Jan 2011
  • Initial release for jQuery UI Slider 1.8.6

© 2010, Keith Wood Valid HTML 4.01 Strict