JavaScript API
Full description of range slider settings, methods and callbacks
A slider is built from a handle (also called a thumb, .irs-handle) that the user drags,
a value label above each handle (.irs-single, .irs-from, .irs-to),
a min label and a max label at the ends (.irs-min, .irs-max),
the interval bar (.irs-bar), which runs between the two handles in double type and from the left edge to the handle in single type,
the track the handles move along (.irs-line),
and the grid, which is tick marks (.irs-grid-pol) with grid labels (.irs-grid-text).
| Option | Defaults | Type | Description |
|---|---|---|---|
| Basic setup | |||
| type data-type |
"single" | string | Choose slider type, could be single - for one handle, or double for two handles |
| min data-min |
10 | number | Set slider minimum value |
| max data-max |
100 | number | Set slider maximum value |
| from data-from |
min | number | Start value of the from handle (the left one; the single handle in single type) |
| to data-to |
max | number | Start value of the to handle (the right one). Only in double type |
| Advanced setup | |||
| step data-step |
1 | number | Set the slider's step. Always > 0. Could be fractional. Values are rounded to the decimals of step, so min: 0.5, step: 1 gives 0.5, 2, 3 ... See step_from_min to keep the scale on min. |
| step_from_min data-step-from-min |
false | boolean | Count the steps from min instead of from zero. With min: 0.5, step: 1 the values are 0.5, 1.5, 2.5 ... instead of 0.5, 2, 3 ... Grid labels, handle limits and min_interval / max_interval follow the same scale; a value off the scale is moved to the nearest point. |
| values data-values |
[] | array | Set up your own array of possible slider values. Entries could be numbers or strings. When the array is set, min, max and step are ignored. A numeric-looking string is converted to a number unless values_raw is set. |
| values_raw data-values-raw |
false | boolean | Keep the values entries exactly as given: "20.0" stays "20.0" on the label, in the input value and in from_value / to_value. Without it a numeric-looking entry becomes the number 20. |
| keyboard data-keyboard |
true | boolean | Activates keyboard controls. Move left: ←, ↓, A, S. Move right: →, ↑, W, D. |
| Grid setup | |||
| grid data-grid |
false | boolean | Enables grid of values. |
| grid_margin data-grid-margin |
true | boolean | Add a grid margin on the left and right. |
| grid_num data-grid-num |
4 | number | Number of grid units. |
| grid_snap data-grid-snap |
false | boolean | Snap the grid to the slider's step (step param). If activated, grid_num will not be used. Max 50 steps. |
| Interval control | |||
| drag_interval data-drag-interval |
false | boolean | Let the user drag the whole interval by its bar. Only in double type |
| drag_over_limit data-drag-over-limit |
false | boolean | Let a dragged handle push the other handle instead of stopping at it. Works with mouse and touch drag, respects min_interval, max_interval, from_fixed and to_fixed. Only in double type |
| min_interval data-min-interval |
— | number | Smallest interval between the handles. Only in double type |
| max_interval data-max-interval |
— | number | Largest interval between the handles. Only in double type |
| Handles control | |||
| from_fixed data-from-fixed |
false | boolean | Fix the position of the from handle. |
| from_min data-from-min |
min | number | Set the minimum limit for the from handle. |
| from_max data-from-max |
max | number | Set the maximum limit for the from handle. |
| from_shadow data-from-shadow |
false | boolean | Highlight the limits for the from handle. |
| to_fixed data-to-fixed |
false | boolean | Fix the position of the to handle. |
| to_min data-to-min |
min | number | Set the minimum limit for the to handle. |
| to_max data-to-max |
max | number | Set the maximum limit for the to handle. |
| to_shadow data-to-shadow |
false | boolean | Highlight the limits for the to handle. |
| UI control | |||
| skin data-skin |
"flat" | string | Choose the skin to use: flat, big, modern, round, sharp, square. |
| hide_min_max data-hide-min-max |
false | boolean | Hides min and max labels |
| hide_from_to data-hide-from-to |
false | boolean | Hide from and to labels |
| force_edges data-force-edges |
false | boolean | Keep the value labels, and the first and last grid labels, inside the container instead of letting them overhang its edges. |
| extra_classes data-extra-classes |
— | string | Add extra CSS classes to the slider container |
| block data-block |
false | boolean | Locks slider and makes it inactive (visually). input is NOT disabled. Can still be sent with forms. |
| Prettify numbers | |||
| prettify_enabled data-prettify-enabled |
true | boolean | Improve readability of long numbers. 10000000 → 10 000 000 |
| prettify_separator data-prettify-separator |
" " | string | Set up your own separator for long numbers. 10 000, 10.000, 10-000 etc. An empty string disables the separator. |
| prettify data-prettify |
null | function, string | Set up your own prettify function. Can be anything. For example, you can set up unix time as slider values and then transform them into readable dates. Can also be a string with the name of a global function. |
| prettify_grid data-prettify-grid |
null | function, string | Set up your own prettify function for the grid labels only. Falls back to prettify, then to default formatting. Not used in values mode. Can also be a string with the name of a global function. |
| prettify_min_max data-prettify-min-max |
null | function, string | Set up your own prettify function for the min and max labels only. Falls back to prettify, then to default formatting. Not used in values mode. Can also be a string with the name of a global function. |
| prettify_all_values data-prettify-all-values |
false | boolean | In values mode, also run prettify on non-numeric entries. |
| prefix data-prefix |
— | string | Set prefix for values. Will be set up right before the number: $100 |
| min_prefix data-min-prefix |
— | string | Special prefix, used only for the minimum value. Will be shown before the min label. For example: From: 0 — 100 |
| max_prefix data-max-prefix |
— | string | Special prefix, used only for the maximum value. Will be shown before the max label. For example: 0 — Up to: 100 |
| postfix data-postfix |
— | string | Set postfix for values. Will be set up right after the number: 100k |
| max_postfix data-max-postfix |
— | string | Special postfix, used only for the maximum value. Shown once the value reaches the maximum. For example 0 — 100+ |
| decorate_both data-decorate-both |
true | boolean | Used for "double" type and only if prefix or postfix was set up. Determine how to decorate close values. For example: $10k — $100k or $10 — 100k |
| values_separator data-values-separator |
" — " | string | Set your own separator for close values. Used for double type. Default: 10 — 100. Or you may set: 10 to 100, 10 + 100, 10 → 100 etc. |
| Data control | |||
| input_values_separator data-input-values-separator |
";" | string | Separator for double values in input value property. Default FROM;TO. Only for double type |
| disable data-disable |
false | boolean | Locks slider and makes it inactive. input is disabled too. Invisible to forms. |
| Callbacks | |||
| scope — |
null | object | Scope for callbacks. Pass any object. Callback will be executed like this: onChange.call(scope); |
| onStart — |
null | function | Callback. Is called once when the slider is created, before its first render. |
| onChange — |
null | function | Callback. Is called on each value change while the user interacts with the slider. Not called on update, reset or a container resize. |
| onFinish — |
null | function | Callback. Is called when the user releases a handle, and also right after a keyboard move or a click on the track. |
| onUpdate — |
null | function | Callback. Is called when the slider is modified by the update or reset method. |
| onInit — |
null | function | Callback. Is called once, right after the first render. For a slider that starts hidden, wait until it becomes visible before touching the DOM. |
Callback data
Every callback receives one object as its first argument:
{
"input": object, // jQuery reference to the input
"slider": object, // jQuery reference to the slider container
"min": 0, // MIN value
"max": 100000, // MAX value
"from": 10000, // FROM value
"from_percent": 10, // FROM value in percent
"from_value": null, // entry from the values array (null unless values is used)
"from_min": null, // FROM minimum limit (null if unset)
"from_max": null, // FROM maximum limit (null if unset)
"to": 90000, // TO value
"to_percent": 90, // TO value in percent
"to_value": null, // entry from the values array (null unless values is used)
"to_min": null, // TO minimum limit (null if unset)
"to_max": null, // TO maximum limit (null if unset)
"min_pretty": "0", // MIN formatted
"max_pretty": "100 000", // MAX formatted
"from_pretty": "10 000", // FROM formatted
"to_pretty": "90 000" // TO formatted
}
Every callback receives the same object, which the plugin rewrites on every change; copy it
(for example with $.extend({}, data)) if you need to keep a snapshot.
In values mode from and to hold the index of the selected entry, not the entry itself.
from_value and to_value hold the entry at that index, and from_pretty and
to_pretty hold its formatted label. min and max hold the first and last
index of the values array. A numeric-looking entry such as "20.0" comes back as the number 20 unless
values_raw is set.
Public methods
Calling ionRangeSlider() again on an input that already has a slider does nothing.
To change settings, take the instance from $(input).data("ionRangeSlider") and call update() on it.
// 1. Initialise the slider
$(".js-range-slider").ionRangeSlider();
// 2. Save the instance to a variable
var my_range = $(".js-range-slider").data("ionRangeSlider");
// 3. Update the slider (this will move the handles)
my_range.update({
from: 300,
to: 400
});
// 4. Reset the slider to its initial values
my_range.reset();
// 5. Destroy the instance
my_range.destroy();
Demos
Time to see some range sliders in action!
Demo
2.5.0