Press "Enter" to skip to content

Pure Javascript Animated Customizable Range Slider | rSlider.js

Single/Range Slider Plugin is a pure JS library to dynamically render nice range sliders with custom scales, labels, and tooltips.

range slider image change, range slider with custom steps, html range slider with labels, responsive range slider javascript, range slider with scale

How to make use of it:

1. Add the rSlider.css style sheet and rSlider.js javascript to your HTML page.

<link rel="stylesheet" href="css/rSlider.min.css">
<script src="js/rSlider.min.js"></script>

2. Create a plain text input field for the range slider.

<input type="text" id="slider" class="slider">

3. Create a new range slider from the text field.

var mySlider = new rSlider({
    target: '#slider',
    values: [2008, 2009, 2010, 2011, ...],
    range: true // range slider
});

4. More configurations to customize the range slider.

var mySlider = new rSlider({
    target: '#slider',
    values: [2008, 2009, 2010, 2011, ...],
    range: true // range slider
    set:    null, // an array of preselected values
    width:    null,
    scale:    true,
    labels:   true,
    tooltip:  true,
    step:     null, // step size
    disabled: false, // is disabled?
    onChange: null // callback
});

5. API methods.

// Returns selected values.
mySlider.getValue();
// Disables the range slider
mySlider.disabled(true);
// Callback
mySlider.onChange(function (values) { 
  // argument values represents current values 
});
// Sets new values
mySlider.setValues(10, 20);
// Destroys the range slider
mySlider.destroy();

Configuration

targetSingle element’s class/id or HTML object e.g. document.getElementById(‘sampleSlider’)
valuesA flat array of values e.g. [1, 2, , 4, 5] or object e.g. {min: 1, max: 10}.
stepWhile using an object value {min: 0, max: 100} the step can be defined e.g. 10
rangeBoolean (true or false) to set if the slider is a range or single type (default false)
setA flat array of one (single slider) or two (range slider) values to set initial values (optional)
widthNumber or string value (e.g. 400 or ‘400px’) to set the slider width (optional). Default the closest parent div width is used.
scaleBoolean (true or false) to show or hide scale (default true).
labelsBoolean (true or false) to show or hide scale labels (default true).
tooltipBoolean (true or false) to show or hide tooltips (default true).
disabledBoolean (true or false) to disable/enable slider (default false).

Methods

Methods can be used after a new instance of slider is initiated e.g. slider.getValue();

getValue()Returns selected values.
disabled(true/false)Makes a slider disabled/enabled
onChange(callback)the callback function argument returns current selected values e.g
mySlider.onChange(function (values) { // argument values represents current values });
setValues(start, end)Method gets one (range: false) or two (range: true) parameters and sets the values (see example above).
destroy()Removes an instance of slider e.g. mySlider.destroy();

animated customizable range slider, single/range slider Plugin/Github


See Demo And Download

Official Website(slawomir-zaziablo): Click Here

This superior jQuery/javascript plugin is developed by slawomir-zaziablo. For extra advanced usage, please go to the official website.

Be First to Comment

    Leave a Reply

    Your email address will not be published.