0

I am working on some jQuery UI sliders and I was wondering is there a way to display a range of values instead of just single values. Such as 10-20, 20-30, 30-40 instead of just 10,20,30,40? I would really appreciate any help on this. I know there is a range slider in the API, but I am trying to get it to snap to the range increments.

Here is a jsfiddle for a working example

$(function() {
//age range function
$("#ageRangeSlider").slider({
  value: 10,
  min: 0,
  max: 100,
  step: 10,
  slide: function(event, ui) {
    $("#yourAgeRange").val(ui.value);
  }
});
$("#yourAgeRange").val($("#ageRangeSlider").slider("value"));
});

<p>
  <label for="yourAgeRange">Your age range:</label>
  <input type="text" id="yourAgeRange" style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="ageRangeSlider"></div>
4
  • jqueryui.com/slider/#range Commented Jun 25, 2014 at 1:58
  • I want it to snap to the increments. Let me clarify in the posting. Commented Jun 25, 2014 at 2:00
  • jsfiddle.net/SCNGa/2 Commented Jun 25, 2014 at 2:00
  • i don't think its any different you just need to specify the range:true and starting positions Commented Jun 25, 2014 at 2:01

1 Answer 1

2

Add range and starting values to the slider

  values:[50,100],
  range:true,

jsfiddle

Update: OP wants the whole slider range to move when you drag a handle. I found this stackoverflow and modified his code to get it working... See the JSBin

Sign up to request clarification or add additional context in comments.

6 Comments

That does work, but then there are two toggles on the slider. Is there any way to have just one while keeping the range?
events are not updating as I would expect. here's something that does what you want, although it allows you to adjust the range ends, if you drag the range in the middle the two ends move with it. stackoverflow.com/questions/5955343/…
ok I got it jsfiddle.net/Swd9S/150 Don't hesitate to give the other guy a +1. I gave him one as well.
Thanks so much. I love stackoverflow and everyone that helps people like me on here!
Justin, you have to add the step value back in... (jsfiddle.net/Swd9S/151)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.