Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI Slider: Range with 3 handles, and configurable colors?

I would like a jQuery UI slider that has five differently colored ranges defined by three handles. (So the first range would be handle 0 - handle 1, and the second range would be handle 1 to handle 2.) Is this possible through configuration, or must I hack it? If I have to modify the source, is there any guidelines for how to go about doing that?

Update: What I'm looking for in terms of ranges is:

| --- color 1 ----- handle1 --------- color 2 ------------- handle2 ------- color3 --------- handle3 -----color 4 ----|

(hopefully that makes sense.)

like image 262
Nick Heiner Avatar asked Jan 19 '11 04:01

Nick Heiner


3 Answers

The range option defined in the jquery ui slider documentation does indeed limit the slider to only 2 handles. You need to create several elements when the slider raises the 'slide' or 'change' event and set the position of these manually, this way you can create a slider with multiple handles and multiple ranges which you can apply custom css to. See fiddle for a working example.

http://jsfiddle.net/AV3G3/3/

like image 142
fungus1487 Avatar answered Oct 20 '22 18:10

fungus1487


You probably want to use a range slider and pass in an array of 3 values to create 3 handles (according to the docs):

The slider widget will create handle elements with the class 'ui-slider-handle' on initialization. You can specify custom handle elements by creating and appending the elements and adding the 'ui-slider-handle' class before init. It will only create the number of handles needed to match the length of value/values. For example, if you specify 'values: [1, 5, 18]' and create one custom handle, the plugin will create the other two.

like image 1
coreyward Avatar answered Oct 20 '22 17:10

coreyward


If you don't insist on jQuery UI, noUiSlider can give ranges different classes and supports multiple handles - just as you ask. This example demonstrates how to color the ranges.

like image 1
Fanky Avatar answered Oct 20 '22 18:10

Fanky