views:

548

answers:

1

I'm trying to get the jQuery slider to have set values to slide to as opposed to every number between the min & max amounts.

I'm wanting "0, 25, 50, 100, 250, 500" as the only amounts people can slide too but can't work out how it's done. Putting them in the "Values" part doesn't seem to do anything.

<script type="text/javascript">
$(function() {
 $("#slider-range").slider({
  range: true,
  min: 0,
  max: 500,
  values: [100, 250],
  slide: function(event, ui) {
   $("#amount").val('Miles: ' + ui.values[0] + ' - ' + ui.values[1]);
  }
 });
 $("#amount").val('Miles: ' + $("#slider-range").slider("values", 0) + ' - ' + $("#slider-range").slider("values", 1));
});
</script>
+4  A: 

The values initializer is for providing the starting positions of multiple-thumb sliders.

I would provide an array of the possible values, change the slider to map over the range of that array, and then change your presentation bit to read from the appropriate array element.

$(function() {
    var valMap = [0, 25, 50, 100, 250, 500];
    $("#slider-range").slider({
     min: 0,
     max: valMap.length - 1,
     values: [0, 1],
     slide: function(event, ui) {                        
      $("#amount").val('Miles: ' + valMap[ui.values[0]] + ' - ' + valMap[ui.values[1]]);                
     }       
    });
    $("#amount").val('Miles: ' + valMap[$("#slider-range").slider("values", 0)] + ' - ' + valMap[$("#slider-range").slider("values", 1)]);
});
great_llama