jQuery UI Slider (setting programmatically)

前端 未结 12 1383
借酒劲吻你
借酒劲吻你 2020-12-02 15:04

I\'d like to modify the sliders on-the-fly. I tried to do so by using

$(\"#slider\").slider(\"option\", \"values\", [50,80]);

This call wil

相关标签:
12条回答
  • 2020-12-02 15:32

    In my case with jquery slider with 2 handles only following way worked.

    $('#Slider').slider('option',{values: [0.15, 0.6]});
    
    0 讨论(0)
  • 2020-12-02 15:34

    Finally below works for me

    $("#priceSlider").slider('option',{min: 5, max: 20,value:[6,19]}); $("#priceSlider").slider("refresh");

    0 讨论(0)
  • 2020-12-02 15:38

    Here is working version:

    var newVal = 10;
    var slider = $('#slider');        
    var s = $(slider);
    $(slider).val(newVal);
    $(slider).slider('refresh');
    
    0 讨论(0)
  • 2020-12-02 15:42

    If you need change slider values from several input, use it:

    html:

    <input type="text" id="amount">
    <input type="text" id="amount2">
    <div id="slider-range"></div>
    

    js:

        $( "#slider-range" ).slider({
        range: true,
        min: 0,
        max: 217,
        values: [ 0, 217 ],
        slide: function( event, ui ) {
            $( "#amount" ).val( ui.values[ 0 ] );
            $( "#amount2" ).val( ui.values[ 1 ] );
        }
        });
    
    $("#amount").change(function() {
        $("#slider-range").slider('values',0,$(this).val());
    });
    $("#amount2").change(function() {
        $("#slider-range").slider('values',1,$(this).val());
    });
    

    https://jsfiddle.net/brhuman/uvx6pdc1/1/

    0 讨论(0)
  • 2020-12-02 15:43

    It depends on if you want to change the sliders in the current range or change the range of the sliders.

    If it is the values in the current range you want to change, then the .slider() method is the one you should use, but the syntax is a bit different than you used:

    $("#slider").slider('value',50);
    

    or if you have a slider with two handles it would be:

    $("#slider").slider('values',0,50); // sets first handle (index 0) to 50
    $("#slider").slider('values',1,80); // sets second handle (index 1) to 80
    

    If it is the range you want to change it would be:

    $("#slider").slider('option',{min: 0, max: 500});
    
    0 讨论(0)
  • 2020-12-02 15:43

    For me this perfectly triggers slide event on UI Slider :

    hs=$('#height_slider').slider();
    hs.slider('option', 'value',h);
    hs.slider('option','slide')
           .call(hs,null,{ handle: $('.ui-slider-handle', hs), value: h });
    

    Don't forget to set value by hs.slider('option', 'value',h); before the trigger. Else slider handler will not be in sync with value.

    One thing to note here is that h is index/position (not value) in case you are using html select.

    0 讨论(0)
提交回复
热议问题