UI Sliders

Complex range example

Notes

noUiSlider is a range slider without bloat. It offers a ton off features, and it is as small, lightweight and minimal as possible, which is great for mobile use on the many supported devices, including iPhone, iPad, Android devices & Windows (Phone) 8 desktops, tablets and all-in-ones. It works on desktops too, of course!

  • Responsive design friendly
  • Touch support for iOS, Android & Windows (phone)
  • Draggable range
  • No jQuery, jQueryUI or other dependencies
  • Tested in IE9 - IE11, Edge, Chrome, Opera, Firefox & Safari

noUiSlider works with pretty much any device, mouse, touchscreen or both, and it'll work beautifully in responsive designs. Have you tried this documentation on your phone?

- - - - - -

Colorpicker

Notes

We'll initialize all sliders with the same options, and use the slide callback to keep to color in sync with the slider values. This callback fires when the slider is moved by sliding, or when it is clicked or tapped.

Using HTML5 input elements

Notes

noUiSlider is perfectly fine serializing values to any element with a .val() method, so lets try using type="number" and <select>.

Note that if your browser doesn't support an input type, it will just assume "text". If you'd like to know more, consider reading this article.

We'll append <option> elements to the <select> dynamically.

Non linear slider

Notes

One of noUiSlider's core features is the ability to divide the range in a non-linear fashion. Stepping can be applied, too! The example on the right shows where the handles are on the slider range in values and percentages.

Locking sliders together

Notes

Two cross-updating sliders can be created using a combination of the change and slide events.

Colored Connect Elements

Notes

noUiSlider's connect elements can be individually colored or otherwise styled.

Changing the slider by keypress

Notes

To keep the library small, features like keyboard interaction haven't been included. However, adding features to input fields linked to a slider is easy. noUiSlider provides API's to help you. In this example, pressing the keyboard arrow keys will increase/decrease the slider by one step.

This example uses the 'step' API to determine by how much the slider should be changed. You don't need this function if your slider is linear. In that case, increase/decrease the value with the ammount of your step.

We'll listen to keydown on the '#input-with-keypress' element, and pass the event to a function so we can read the code that identifies the key.

Note that the slider value will be a string, so we'll need to parse it to an integer.

Skipping steps

Notes

When using a stepped slider, your configuration may require that certain steps aren't available. Using the snap feature, this effect can be created.

Notice how 40 and 80 can't be selected on the slider.

Using the slider with huge numbers

Notes

If you are working with arbitrarily large numbers, you should not use these directly in noUiSlider, as you'll run into some JavaScript limitations. Instead, you should map your values to an array.

Numbers is JavaScript are Double Precision Floats, which can store numbers up to 2^53 (9007199254740992) precisely. For reference, see this StackOverflow question, or issue #427 filed on GitHub.

As an example, see the 'range' option for a RAM selector offering 14 steps from 512MB to 8GB. The 'step' are ommited for clarity. The values are provided as bytes. A better solution would be to abstract the byte values away from the slider, looking up the byte values in an array. This keeps the slider configuration simple and prevents issues with floating point precision.

(These values fit within the limit just fine, but demonstrate the point really well!)

Working with dates

Notes

As all dates in JavaScript can be represented as time, noUiSlider can handle them, too. This example will show you how to convert dates to numerical ranges, and then use the update event to display them in a pretty format.

We'll be creating timestamps from strings. In order to do this easily, we'll define a new helper function. This function accepts a string, creates a new Date and then returns it as a timestamp.

In in overview below you'll find the code used to run this example. For readability, all helper functions have been moved into their own tab.

Soft limits

Notes

If you want to disable the edges of a slider, the set event can be used to reset the value if a limit is passed. Note how the handle 'bounces back' when it is released below 20 or above 80. noUiSlider also supports disabling edges altogether, which can be done using the padding option.

Layout Options


Skin Color