为此使用离子范围滑块。我正在尝试调用我设置为记录缩放的美化函数的值。我的日志缩放有效,但是当我尝试将其调用回我的其他异步函数时,我无法获得相同的结果。
我希望我从 prettify 函数得到的结果通过 onStart、OnChange、onFinish 函数。
onStart: function(data) {
imprValue = data.from;
console.log("onstart:" + imprValue);
inputValues();
},
onChange: function(data) {
imprValue = data.from;
console.log("onchange:" + imprValue);
inputValues();
},
onFinish: function(data) {
imprValue = prettify();
console.log("onfinish:" + imprValue);
inputValues();
},
prettify: function(n) {
// current position
var position = Math.floor(n / this.max * 100);
// position will be between 0 and 100
var minPos = 0,
maxPos = 100;
// calculate logarithms
var minLog = Math.log(this.min),
maxLog = Math.log(this.max);
// calculate adjustment factor
var scale = (maxLog-minLog) / (maxPos-minPos);
// round numbers
n = Math.floor(Math.exp(minLog + scale * (position - minPos)));
console.log("prettify function:" + n);
return n;
}
Jsfidde在这里:http: //jsfiddle.net/jsbegin/7dbowqfd/61/