雅,这很好。但您显示的示例是固定增量值。但我正在寻找非线性值,例如{13,18,27,56,100}
答案 0 :(得分:1)
您可以使用对数刻度。
假设maxValue
是您允许的最大值。然后,您可以像这样定义方法myLog(x)
:
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);
}
然后,您可以简单地将默认滑块值转换为对数值:
var outputString = "€" + myLog( $( "#slider-range" ).slider( "values", 0 ) ) + " - €" + myLog( $( "#slider-range" ).slider( "values", 1 )) ;
$( "#amount" ).val(outputString);