使用鼠标上下更改值时的UI Spinner Bug [英] UI spinner bug when changing value using mouse up and down
问题描述
我将十进制微调器添加到了我的网站.
I added the decimal spinner to my site.
我的价值是56.20.当我改变使用鼠标滚轮时,我期望是57.20,但是现在显示为57:00.
My value was 56.20. When I change use mouse wheel up, I am expecting 57.20, but now it is showing 57:00.
该功能如下所示:
<script>
$(function() {
$( "#spinner" ).spinner({
step: 1.00,
numberFormat: "n"
});
$( "#culture" ).change(function() {
var current = $( "#spinner" ).spinner( "value" );
Globalize.culture( $(this).val() );
$( "#spinner" ).spinner( "value", current );
});
});
</script>
我也包括了演示
推荐答案
我完全不认为这是一个错误,只是简单地将其四舍五入-我认为这是 spinner.js ,该操作将汇总:
I don't think it's a bug at all sorry to say, it's simply rounding up - I think this the part in the jQuery code within the spinner.js that actions the round up:
在 _spin()
期间:
value = this._adjustValue( value + step * this._increment( this.counter ) );
调用 _adjustValue()
:
_adjustValue: function( value ) {
var base, aboveMin,
options = this.options;
// make sure we're at a valid step
// - find out where we are relative to the base (min or 0)
base = options.min !== null ? options.min : 0;
aboveMin = value - base;
// - round to the nearest step
aboveMin = Math.round(aboveMin / options.step) * options.step;
// - rounding is based on 0, so adjust back to our base
value = base + aboveMin;
// fix precision from bad JS floating point math
value = parseFloat( value.toFixed( this._precision() ) );
// clamp the value
if ( options.max !== null && value > options.max) {
return options.max;
}
if ( options.min !== null && value < options.min ) {
return options.min;
}
return value;
},
来源:但是您可以尝试的是在旋转& ;;之前获取价值.然后在完成旋转后根据之前的以下两个回调事件重新调整值:
But what you could try, is catching the value before spinning & then re-adjusting the value after a completed spin, based on what you had before with the two callback events below:
var beforeSpin = 1.00;
$( "#spinner" ).spinner({
step: 1.10,
numberFormat: "n",
start: function( event, ui ) {
beforeSpin = ui.value;
},
//or stop: function(){}
spin: function( event, ui ) {
//Do some re-value
//funciton based on old value
}
});
那,或者根据您的需要重新编程 _adjustValue:function()
-毕竟是开源的:)
That, or re-program the _adjustValue: function()
to your needs - Open source after all :)
这篇关于使用鼠标上下更改值时的UI Spinner Bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!