Alex T
Alex T

Reputation: 3754

jQuery slider incorrect behaviour

I created slider using the following code available on jsfiddle:

http://jsfiddle.net/3cpsoft1/

However there is some weird behavior when the max value element of the slider is changing itself when left slider is activated.

I think this has something to do with ui part of the slider function but I don't know what is affecting it.

So at first the correct value is 0.0474 and it should stay that way. But somehow it becomes negative as if one value of step was deducted from it. You can see that on the fiddle i provided. Is there a way to fix this?

Upvotes: 0

Views: 53

Answers (1)

Vincent
Vincent

Reputation: 61

When you divide your total length by the step, you'll end up with a small remainder which is not able to render. Therefore, you must set it to the smallest decimal value you want slide over. Also, your max value should be outside the bound.

$( function() {
    $( "#slider-range-max" ).slider({
      range: true,
      min: -1000,
      max: 0.475,
      step: .001,
      values: [-1000,0.474],
      slide: function( event, ui ) {
        $( "#amount1" ).val( ui.values[0] );
        $( "#amount2" ).val( ui.values[1] );
      }
    });
    $( "#amount1" ).val( -1000 );
    $( "#amount2" ).val( 0.474);
  } );

Upvotes: 1

Related Questions