Is there a way to make the jQuery UI slider start with 0 on top instead of on bottom?

前端 未结 4 958
伪装坚强ぢ
伪装坚强ぢ 2021-01-08 00:19

Look at this demo of the jQuery UI Slider.

Notice how when the handle is down the bottom, the value is 0?

Is there a way to reverse this, so the handle up t

相关标签:
4条回答
  • 2021-01-08 00:37

    Probably, usage of negative values will be more elegant:

    $('#slider').slider({
        min: -100,
        max: 0,
        value: -50,
        step: 1
    });
    

    Just use absolute value, instead of an actual one, where you need it.

    0 讨论(0)
  • 2021-01-08 00:38

    You could just turn it upside down using css3.

    #slider {
         -moz-transform: rotate(180deg);
         -webkit-transform: rotate(180deg);
         -ms-transform: rotate(180deg);
         -o-transform: rotate(180deg);
         transform: rotate(180deg);
    }
    
    0 讨论(0)
  • 2021-01-08 00:44
    $(function() {
        $("#slider-vertical").slider({
          orientation: "vertical",
          range: "max", // <--- needed...
          min: 0,
          max: 100,
          value: 60,
          slide: function(event, ui) {
            $("#amount").val(100 - ui.value); // basic math operation..
          }
        });
      });
    

    demo... ​

    0 讨论(0)
  • 2021-01-08 00:52

    Don't reverse it, take the easy way out :) Just subtract the value from your max, for example:

    $("#slider-vertical").slider({
        orientation: "vertical",
        range: "min",
        min: 0,
        max: 100,
        slide: function(event, ui) {
            $("#amount").val(100 - ui.value);
        }
    });
    

    This just goes max-value, effectively reversing it, you can see a quick demo here.

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