945,066 Members | Top Members by Rank

Ad:
Feb 16th, 2011
0

Multiple handles in a jQuery Range slider

Expand Post »
I need to use jQuery range slider for setting up limits for multiple ranges which are interdependent, something that is similar to slider that we use for hard disk space allocation during OS installation but mine is a web applcation and the data necessary would be fetched from DB. I've tried the following code but I couldn't get two ranges. Only two handles are active.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $(function() {
  2. $( "#slider-range" ).slider({
  3. range: true,
  4. min: 0,
  5. max: 1000,
  6. values: [ 75, 300, ],
  7. slide: function( event, ui ) {
  8. $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
  9. }
  10. });
  11. $( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
  12. " - $" + $( "#slider-range" ).slider( "values", 1 ) );
  13. });
and

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <div class="demo">
  2.  
  3. <p>
  4. <label for="amount">Price range:</label>
  5. <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;" />
  6. </p>
  7.  
  8. <div id="slider-range" class="ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all">
  9. <a href="#" class="ui-slider-handle ui-state-default ui-corner-all" style="left: 20.1%;"></a>
  10. <a href="#" class="ui-slider-handle ui-state-default ui-corner-all" style="left: 30.1%;"></a>
  11. <a href="#" class="ui-slider-handle ui-state-disabled ui-corner-all" style="right: 99.5%;"></a>
  12. <a href="#" class="ui-slider-handle ui-state-disabled ui-state-default ui-corner-all" style="left: 99.5%;"></a>
  13. </div>
  14.  
  15. </div>

How can i make more handles active in same slider without overlapping them?

Thanks in advance!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vigneshd90 is offline Offline
5 posts
since Feb 2011
Feb 17th, 2011
1
Re: Multiple handles in a jQuery Range slider
Vignesh,

Making multiple handles is easy :
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $(function() {
  2. $mySlider = $( "#slider-range" );
  3. $mySlider.slider({
  4. // range: true,//don't set range
  5. min: 0,
  6. max: 1000,
  7. values: [ 75, 125, 175, 225 ],
  8. slide: function( evt, ui ) {
  9. a = [];
  10. for(var i=0; i<ui.values.length; i++) {
  11. a.push(ui.values[i]);
  12. }
  13. $( "#amount" ).val( "$" + a.join(" - " + "$") );
  14. }
  15. });
  16. $( "#amount" ).val(
  17. ["$" + $mySlider.slider("values", 0),
  18. "$" + $mySlider.slider("values", 1),
  19. "$" + $mySlider.slider("values", 2),
  20. "$" + $mySlider.slider("values", 3)].join(" - ")
  21. );
  22. });
Giving the slider "multi-range" behaviour is not so easy. I played around for a bit a couldn't come up with 100% satisfactory code. The big issue, as you say, is preventing overlap, which would take a bit of development effort and possibly approached in a modified version of "slider", otherwise the interface appears to expose too little of the inner workings.

Another approach (easier/harder?) would be to have a stack of interlinked range-sliders, set up such that the upper handle of each also moves the lower slider of the next range-slider in the stack ..... and vice versa. This would also involve some development effort but would benefit from basic range slider behaviour being already in place.

These are my best thoughts. Nothing more, I'm afriad.

Airshow
Last edited by Airshow; Feb 17th, 2011 at 3:36 pm.
Sponsor
Reputation Points: 318
Solved Threads: 358
WiFi Lounge Lizard
Airshow is offline Offline
2,530 posts
since Apr 2009
Feb 18th, 2011
0
Re: Multiple handles in a jQuery Range slider
Thanks for the help! If you come to know about the range as well, do post about it! I'll try to find and post as well! Thanks again!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vigneshd90 is offline Offline
5 posts
since Feb 2011
Dec 21st, 2011
0

preventing overlap

Here's a little bit of code to prevent overlap in the above example
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $mySlider.slider({
  2. // range: true,//don't set range
  3. min: 0,
  4. max: 1000,
  5. values: [ 75, 125, 175, 225 ],
  6. slide: function( evt, ui ) {
  7. for(var i = 0, l = ui.values.length; i < l; i++){
  8. if(i !== l-1 && ui.values[i] > ui.values[i + 1]){
  9. return false;
  10. }
  11. else if(i === 0 && ui.values[i] < ui.values[i - 1]){
  12. return false;
  13. }
  14.  
  15. }
  16. }
  17. });
Reputation Points: 10
Solved Threads: 0
Newbie Poster
_superted is offline Offline
1 posts
since Dec 2011
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: options and buttons not quite working correctly in jquery
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Tablesorter jQuery Plugin - a fix





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC