jquery ui slider display values

馋奶兔 提交于 2019-11-30 07:13:34

Just arrange your label container (e.g. I added a div) and when you slide, update it.

Live version : http://jsfiddle.net/8ek4a/5/

Code :

$(function() {
   var labelArr = new Array("", "1 hour", "12 hours", "1 day", "3 day", "1 week");
   $( "#slider" ).slider({
       value:3,
       min: 1,
       max: 5,
       step: 1,
       slide: function( event, ui ) {
          $( "#days" ).val( ui.value );
          $("#label").html(labelArr[ui.value]);
       }
   });
   $( "#days" ).val($( "#slider" ).slider( "value" ) );
   $("#label").html(labelArr[$( "#slider" ).slider( "value" )]);
});​

UPDATE: Now I have come up with this solution to implement indicator. see http://jsfiddle.net/8ek4a/6/

you can try this code

 $(function() {
$("#slider-range").slider({
  range: true,
  min: 12,
  max: 500,
  values: [ 75, 300 ],
  slide: function( event, ui ) {
    $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
  }
});
$( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) + "- $" + $( "#slider-range" ).slider( "values", 1 ) );
});

Now we can use this plugin to display values

$(".slider").slider().slider("pips", {
        first: "pip",
        last: "pip"
    }).slider("float");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link href="https://code.jquery.com/ui/1.10.4/themes/flick/jquery-ui.css" rel="stylesheet"/>
<link href="https://raw.githubusercontent.com/simeydotme/jQuery-ui-Slider-Pips/master/dist/jquery-ui-slider-pips.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<script src="https://raw.githubusercontent.com/simeydotme/jQuery-ui-Slider-Pips/master/dist/jquery-ui-slider-pips.js"></script>

<div class="slider"></div>

Fiddle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!