Ya that is fine. But the example that you are show开发者_高级运维ing is for fixed incremental values. But I am looking for non-linear values e.g., {13,18,27,56,100}
You can use logarithmic scale.
Suppose that maxValue
is your maximum allowed value. Then, you can define a method myLog(x)
like this:
var maxValue = 350;
function myLog(x) {
return roundNumber( Math.pow(maxValue + 1,(x/100)) - 1, 2);
}
function roundNumber(num, dec) {
return Math.round( num * Math.pow(10,dec)) / Math.pow(10,dec);
}
Then, you can simply convert default slider values into logarithmic ones:
var outputString = "€" + myLog( $( "#slider-range" ).slider( "values", 0 ) ) + " - €" + myLog( $( "#slider-range" ).slider( "values", 1 )) ;
$( "#amount" ).val(outputString);
精彩评论