JQuery Slider, how to make “step” size change

后端 未结 12 803
遥遥无期
遥遥无期 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条回答
  •  猫巷女王i
    2020-11-27 11:27

    here's how i did mine. demo here - http://janpatricklara.com/web/extra/jQueryUISliderUnevenSteps.html

    have an array of your desired values

    var amts=[50,100,150,200,225,250,300];
    

    have the slider increment from 0 to the length of the array, with steps of 1. output the value from the index of the array instead of using the slider's actual value.

    this way the increments and steps are evenly distributed. after that you can just grab the value of the label or save it to a var.

    $('#amtslider').slider({
        min:0,
        max:amts.length-1,
        step:1,
        value:0,
        change:function(event, ui){
            //alert(amts[$(this).slider("value")]);
            //alert($(this).slider("value"));
            $('#lbl_amt').val(amts[$(this).slider("value")]);
        },
        slide:function(event, ui){
            $('#lbl_amt').val(amts[$(this).slider("value")]);
        }
    });
    

提交回复
热议问题