JQuery Slider, how to make “step” size change

后端 未结 12 812
遥遥无期
遥遥无期 2020-11-27 10:59

Is it possible to use the JQuery Slider (range slider / dual slider) to have non-linear (non consistent \"step\" size) values?

I want to horizontal Slider to look li

12条回答
  •  孤街浪徒
    2020-11-27 11:03

    Here is my simple solution for a custom (non consistent "step" size) dual-slider (you can modify it to a single-slider if the idea becomes clear) my slider is named "slider-euro", the text-area is named amount-euro as you can see in the code. The idea is to have a slider from 0 to 100 and an array ("realvalues") with 101 places. The slider-value is understood as the place in that array. The only thing is that you have to reference the array when you get the slider values. Here is my Example:

        $(function() {
        var realvalues = [0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 15000, 20000, 25000, 30000, 35000, 40000, 45000, 50000, 55000, 60000, 65000, 70000, 75000, 80000, 85000, 90000, 95000, 100000, 105000, 110000, 115000, 120000, 125000, 130000, 135000, 140000, 145000, 150000, 155000, 160000, 165000, 170000, 175000, 180000, 185000, 190000, 195000, 200000, 205000, 210000, 215000, 220000, 225000, 230000, 235000, 240000, 245000, 250000, 255000, 260000, 265000, 270000, 275000, 280000, 285000, 290000, 295000, 300000, 310000, 320000, 330000, 340000, 350000, 360000, 370000, 380000, 390000, 400000, 450000, 500000, 550000, 600000, 650000, 700000, 750000, 800000, 850000, 900000, 1000000, 1500000, 2000000];
    
        $( "#slider-euro" ).slider({
        range: true,
        min: 0,
        max: 100,
        step: 1,
        values: [ 25, 50 ],
        slide: function( event, ui ) {
        $( "#amount-euro" ).val( realvalues[ui.values[ 0 ]] + " € - " + realvalues[ui.values[ 1 ]] + " €");
        }
        });
        $( "#amount-euro" ).val( realvalues[$( "#slider-euro" ).slider( "values", 0 )] + " € - " + realvalues[$( "#slider-euro" ).slider( "values", 1 )]+" €" );
        });
    

提交回复
热议问题