Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery ui slider - ignore/do not step to increment
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/8646796/jquery-ui-slider-max-value-not-end-of-slider">jQuery UI Slider - max value (not end of slider)</a> </p> </blockquote> <p>I'm using non-linear increments for my ui slider:</p> <pre><code> $(function() { var trueValues = [5, 10, 20, 50, 100, 150, 165]; var values = [10, 20, 30, 40, 60, 90, 100]; var slider = $("#parkSlider").slider({ orientation: 'horizontal', range: "min", value: 40, slide: function(event, ui) { var includeLeft = event.keyCode != $.ui.keyCode.RIGHT; var includeRight = event.keyCode != $.ui.keyCode.LEFT; var value = findNearest(includeLeft, includeRight, ui.value); slider.slider('value', value); $("#amount").val(getRealValue(value)); return false; }, }); function findNearest(includeLeft, includeRight, value) { var nearest = null; var diff = null; for (var i = 0; i &lt; values.length; i++) { if ((includeLeft &amp;&amp; values[i] &lt;= value) || (includeRight &amp;&amp; values[i] &gt;= value)) { var newDiff = Math.abs(value - values[i]); if (diff == null || newDiff &lt; diff) { nearest = values[i]; diff = newDiff; } } } return nearest; } function getRealValue(sliderValue) { for (var i = 0; i &lt; values.length; i++) { if (values[i] &gt;= sliderValue) { return trueValues[i]; } } return 0; } }); </code></pre> <p>I want to ignore the value at 165, and not step to that increment - so the slider can only max at 150, although 150 is not the max value of the slider.</p> <p>A graphic may explain better:</p> <p><img src="https://i.stack.imgur.com/5VGma.png" alt="slider"></p> <p>where I want the position of the slider handle to stop at the 150 value, and not step to the 165 value. (I know I can set the max of the slider, but this is the wrong behavior, as the slider handle then extends past the 150 tick mark)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload