Can't get rangeslider.js to work
Asked Answered
U

5

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/

Unbidden answered 1/12, 2015 at 8:26 Comment(2)
Use this link instead of the CDN collection link in your JSFiddle external resources corrected fiddleHydrobomb
Thanks. I was expecting the slider to have the same design as the examples: 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..Unbidden
G
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 );
    }
});
Geniculate answered 27/5, 2016 at 11:6 Comment(5)
Exactly what I needed to see when I needed to see it.Malorie
the developer should add polyfill: false gotcha in his docs. I just wasted 2 hours fixing everything in the html page before ending up here.Bermuda
tell me about, thats why I added the answer. The docs are poorly written and easy to miss the reason why it wasn't workingGeniculate
Didn't work for me - all I see rendered on the screen is this "1" - <div class="range-output">1</div>Indwell
This is a specific issue for yourself then, create a new issue and send me the SO url and ill take a lookGeniculate
R
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
});
Rheumatic answered 28/6, 2018 at 7:44 Comment(0)
B
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 );
            }
        });
    });
Biathlon answered 20/10, 2017 at 8:15 Comment(0)
C
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>
Chasseur answered 26/8, 2019 at 15:31 Comment(0)
D
0

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

Demirelief answered 21/4, 2020 at 7:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.