开发者

jquery slider with non linear values (Not in a particular series)

开发者 https://www.devze.com 2023-02-28 01:32 出处:网络
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.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消