jquery-rsSliderLens demonstration

With this plug-in, you can change the default input range, from this:

<input type="range">
    

to:

<input type="range">
<script>
        $("input").rsSliderLens();
</script>
    

To use a step 25, you can add a step attribute to the <input> element or add a parameter to the plug-in constructor:

<input type="range">
<script>
    $("input").rsSliderLens({
        step: 25
    });
</script>
    
0255075100
0255075100

The 0 and 100 labels are cropped! No problem, just add a padding space equal to 10% of the slider width:

<input type="range">
<script>
    $("input").rsSliderLens({
        step: 25,
        paddingStart: 0.1,
        paddingEnd: 0.1
    });
</script>
    
0255075100
0255075100

By default <input type="range"> has a range between 0 and 100.
For other ranges, you can add min and max attributes to the <input> element, or in the plug-in constructor:

<input type="range">
<script>
    $("input").rsSliderLens({
        step: 25,
        paddingStart: 0.1,
        paddingEnd: 0.1,
        min: -50,
        max: 150
    });
</script>
    
-50-250255075100125150
-50-250255075100125150

Great, but now the labels overlap each other.
To fix this, you have some options: (click each one for a sample)

Use a range to restrict input even further:

<input type="range">
<script>
    $("input").rsSliderLens({
        width: 300,
        height: 45,
        step: 10,
        paddingStart: 0.1,
        paddingEnd: 0.1,
        range: {
            type: [20, 60],
            draggable: true
        }
    });
</script>
    
0102030405060708090100
0102030405060708090100

Use your mouse to drag the range to other location

If you want labels every 20 positions, but with a step of 1:

<input type="range">
<script>
    $("input").rsSliderLens({
        step: 1,
        paddingStart: 0.1,
        paddingEnd: 0.1,
        ruler: {
            labels: {
                values: [0, 20, 40, 60, 80, 100]
            }
        }
    });
</script>
    
020406080100
020406080100

The same slider, but now with a fixed handle style with a min of 0 and max of 500:

<input type="range">
<script>
        var labels = [];
    for (var i = 0; i <= 500; i+= 20) {
        labels.push(i);
    }
    $("input").rsSliderLens({
        step: 1,
        paddingStart: 0.1,
        paddingEnd: 0.1,
        width: 300,
        max: 500,
        fixedHandle: true,
        ruler: {
            labels: {
                values: labels
            }
        }
    });
</script>
    
020406080100120140160180200220240260280300320340360380400420440460480500
020406080100120140160180200220240260280300320340360380400420440460480500

Using customized events to display current value inside the handle and to style labels:

<input type="range">
<style>
    #custom + .range, // range outside the handle 
    #custom ~ .handle .range { // range inside the handle 
        background: -moz-linear-gradient(left, red 0%, green 100%);
        background: -webkit-linear-gradient(left, red 0%, green 100%);
        background: linear-gradient(to right, red 0%, green 100%);
    }
</style>
<script>
    $("input").rsSliderLens({
        step: 1,
        paddingStart: 0.1,
        paddingEnd: 0.1,
        min: -20,
        max: 20,
        ruler: {
            labels: {
                values: [-20, -10, 0, 10, 20],
        onCustomLabel: function(event, value) {
                    return value > 0 ? '+' + value : value;
                },
                onCustomAttrs: function(event, value) {
                    if (value < 0) return { style: 'fill:red' };
                    if (value > 0) return { style: 'fill:green' };
        // no style defined for zero, so returns nothing (or undefined)
                }
            }
        },
        onCreate: function (event) {
        // append a new child <label> element to the .handle
            $(event.currentTarget).nextAll(".handle").append("<label>");
        },
        onChange: function (event, value) {
        // use the <label> element created at run-time, to display the current value
            var $labelElement = $(event.currentTarget).nextAll(".handle").children("label");
            $labelElement.text(value < 0 ? value : ((value > 0 ? '+' : '') + value));
        }
    });
</script>
    
-20-100+10+20
-20-100+10+20

You have the choice of OnChange or OnFinalChange (recommended for computationally expensive tasks)

<input type="range">
<script>
    $("input").rsSliderLens({
        onChange: function (event, value) {
            $changeLabel.text(value);
        },
        onFinalChange: function (event, value) {
            $finalChangeLabel.text(value);
        }
    });
</script>
    

Did I mention the support for double handle sliders?

<input type="range">
<script>
    $("input").rsSliderLens({
        value: [10, 25]
    });
</script>
    
05101520253035404550556065707580859095100
05101520253035404550556065707580859095100
05101520253035404550556065707580859095100

You can bind the plug-in to any element, not only to an <input type=range>:

<span>Hello world</span>
<script>
    $("span").rsSliderLens({ ruler: { visible: false } });
</script>
    
Hello world
Hello world

<span>
    <img src="./pic1.jpg" width="60" height="40">
    <img src="./pic2.jpg" width="60" height="40">
    <img src="./pic3.jpg" width="60" height="40">
</span>
<script>
    $("span").rsSliderLens({ ruler: { visible: false } });
</script>
    


Or with a little more customization

<span tabindex="0">
    <img src="./pic1.jpg" width="60" height="40">
    <img src="./pic2.jpg" width="60" height="40">
    <img src="./pic3.jpg" width="60" height="40">
</span>
<script>
    $("span").rsSliderLens({
        max: 2,
        step: 1,
        paddingStart: .15,
        paddingEnd: .15,
        ruler: { visible: false }
    });
</script>
    

The tabindex makes the slider keyboard focusable

Responsive design. Please, resize your browser window.

This is possible with the use of relative CSS units.
Don't like the dark layout? You can recompile LESS files to generate the layout you like.


<input type="range">
<script>
    $("span").rsSliderLens();
</script>
    
020406080100
020406080100

020406080100
020406080100

020406080100
020406080100
020406080100
020406080100

You have total flexibility over the style.

Just change the CSS (not the javascript) to give wings to your imagination.

0
5
10
15
20
25
30
35
40
45
50
55
60
65
70
75
80
85
90
95
100
105
110
115
120
125
130
135
140
145
150
155
160
165
170
175
180
185
190
195
200
0
5
10
15
20
25
30
35
40
45
50
55
60
65
70
75
80
85
90
95
100
105
110
115
120
125
130
135
140
145
150
155
160
165
170
175
180
185
190
195
200
-20-10010203040506070
-20-10010203040506070
-20-10010203040506070
  • iPhone
    SE
  • iPhone
    7
  • LG
    G5
  • Samsung
    S7
  • OnePlus
    3
  • HTC
    10
  • Huawei
    P9
  • iPhone
    SE
  • iPhone
    7
  • LG
    G5
  • Samsung
    S7
  • OnePlus
    3
  • HTC
    10
  • Huawei
    P9
very unhappyunhappynormalhappyvery happy
very unhappyunhappynormalhappyvery happy
January
February
March
April
May
June
July
August
September
October
November
December
January
February
March
April
May
June
July
August
September
October
November
December