20

I am trying to use the rangeslider jQuery plugin: http://andreruffert.github.io/rangeslider.js/

However, it doesn't seem to work. What am I doing wrong?

<input
    type="range"
    min="10"                    // default 0
    max="1000"                  // default 100
    step="10"                   // default 1
    value="300"                 // default min + (max-min)/2
    data-orientation="vertical" // default horizontal
>

$( document ).ready(function() {
    $('input[type="range"]').rangeslider();
});

Jsfiddle: http://jsfiddle.net/8n2ckkmr/

user2806026
  • 787
  • 3
  • 10
  • 24
  • Use [this link](https://cdnjs.cloudflare.com/ajax/libs/rangeslider.js/2.0.5/rangeslider.min.js) instead of the CDN collection [link](https://cdnjs.com/libraries/rangeslider.js) in your JSFiddle external resources **[corrected fiddle](http://jsfiddle.net/rwachtler/y471r2t4/)** – Ramiz Wachtler Dec 01 '15 at 08:32
  • Thanks. I was expecting the slider to have the same design as the examples: http://andreruffert.github.io/rangeslider.js/ Would that just be css-styling then? Thought it was default and it doesnt seem like I can target the handle and stuff using css.. – user2806026 Dec 01 '15 at 08:38

5 Answers5

76

The actual answer is down to the polyfill option;

Feature detection the default is true. Set this to false if you want to use the polyfill also in Browsers which support the native <input type="range"> element.

Heres an easy way to get started:

$('input[type="range"]').rangeslider({
    polyfill : false,
    onInit : function() {
        this.output = $( '<div class="range-output" />' ).insertAfter( this.$range ).html( this.$element.val() );
    },
    onSlide : function( position, value ) {
        this.output.html( value );
    }
});
Luke Snowden
  • 4,056
  • 2
  • 37
  • 70
1

What have I learned is that <input> needs to have also attribute [role="input-range"] for this to work:

<input type="range" min="1" max="100" value="10" role="input-range">

$('input[type="range"]').rangeslider({
  polyfill: false
});
Yaseen Ahmad
  • 1,807
  • 5
  • 25
  • 43
Mentori
  • 426
  • 4
  • 10
0

It worked for me also, but only on document ready

 $(document).ready(function() {
        $('[role="range"]').rangeslider({
            polyfill : false,
            onInit : function() {
                this.output = $( '[role="input-range"]' ).html( this.$element.val() );
            },
            onSlide : function( position, value ) {
                this.output.html( value );
            }
        });
    });
0
<input type="range" min="10" max="1000" step="10" value="300" />
<script src="~/lib/jquery/dist/jquery.js"></script>
<script src="~/js/rangeslider.js" asp-append-version="true"></script>
<script>
    $('input[type="range"]').rangeslider({
       polyfill: false,
       onInit: function () {
           this.output = $('<div class="range-output" 
           />').insertAfter(this.$range).html(this.$element.val());
            },
            onSlide: function (position, value) {
                this.output.html(value);
            }
        });</script>
ecklerpa
  • 159
  • 1
  • 7
0

make sure to have the correct path to the js files and dont forget to add rangeslider.css within your page

Keusta
  • 11
  • 4