对数滑块返回NaN

时间:2011-01-25 05:41:13

标签: javascript algorithm slider logarithm

我正试图按照Logarithmic slider的例子。

这是我正在使用的代码:

Timeline._MIN_PER_MINUTE = 1;
Timeline._MIN_PER_HOUR = Timeline._MIN_PER_MINUTE * 60.0;
Timeline._MIN_PER_DAY = Timeline._MIN_PER_HOUR * 24.0;
Timeline._MIN_PER_WEEK = Timeline._MIN_PER_DAY * 7.0;
Timeline._MIN_PER_MONTH = Timeline._MIN_PER_WEEK * 4.0;
Timeline._MIN_PER_YEAR = Timeline._MIN_PER_MONTH * 12.0;

var scale_down = 0.00001;
var scale_up = 100000;
Timeline._SLIDER_MIN = 0;
Timeline._SlIDER_MAX = 100;
Timeline._SLIDER_STEP = 1;

Timeline._scale = function (value) {
  var minIn = Timeline._SLIDER_MIN;
  var maxIn = Timeline._SLIDER_MAX;

  var minOut = Math.log(Timeline._MIN_PER_MINUTE);
  var maxOut = Math.log(Timeline._MIN_PER_YEAR);

  var scale = (maxOut - minOut) / (maxIn - minIn);

  return Math.exp(minOut + scale * (value - minIn));
};

Timeline._sliderChangedHandler = function(id){
  var val = Timeline._scale($('#scale_slider' + id).val());
  alert(val);
};

出于某种原因,我得到NaN作为结果。 有人知道我做错了吗?

1 个答案:

答案 0 :(得分:1)

使用它 var val = Timeline._scale(parseInt($('#scale_slider'+ id).val(),10));