我有一个 jQuery UI 滑块:
I have a jQuery UI slider:
$('div.slider').slider({
range: true,
step: 250,
min: 1000,
max: 500000,
values: [1000,500000],
change: function(event, ui){
console.log($(this).slider('values', 0)+','+$(this).slider('values', 1));
},
slide: function(event, ui){
console.log($(this).slider('values', 0)+','+$(this).slider('values', 1));
}
});
出于某种奇怪的原因,当释放滑块(鼠标上移)时,该值与原来的值略有不同.幻灯片事件返回的内容与更改事件不同.任何人有任何想法可能导致此问题以及我如何解决它?
For some odd reason, when releasing the slider (mouseup) the value changes slightly from what it was. The slide event is returning something different than what the change event is. Anyone have any ideas what might be causing this and how I could solve it?
我将在更改事件的回调中进行非常激烈的操作(这意味着我不能只使用 sldie),而且还需要实时显示滑块的值,所以我不能只使用一个或另一个.
I'm going to have a pretty intense operation in the callback for the change event (meaning I can't just use sldie), but also need to show the values of the slider live, so I can't use just one or the other.
这里有一个关于这种奇怪行为的小提琴:http://jsfiddle.net/5W6Zh/
Here's a fiddle with this oddity in action: http://jsfiddle.net/5W6Zh/
提前致谢
我们今晚(昨晚和过去几个月)遇到了这个问题.我们修复它的方法是使用 ui.value 和 ui.values[0] 而不是 $("#slider").slider('values',0).
we ran into this tonight (and last night, and for the past few months). What we did to fix it was use ui.value and ui.values[0] instead of $("#slider").slider('values',0).
使用这个:
change: function(event, ui) {
$('.values').text(ui.values[0] + ',' + ui.values[1]);
}
代替:
change: function(event, ui) {
$('.values').text($(this).slider('values', 0) + ',' + $(this).slider('values', 1));
}
我分叉了你的 jsfiddle 并使它工作:http://jsfiddle.net/danhixon/9JdhU/1/
I forked your jsfiddle and made it work: http://jsfiddle.net/danhixon/9JdhU/1/
老实说,如果没有您的问题和 jsfiddle,我认为我不会找到解决方案 - 我一直将它与 jquery-ui 演示进行比较,直到我发现这种差异.
Honestly I don't think I would have found the solution without your question and jsfiddle - I kept comparing it to the jquery-ui demo until I found this difference.
这篇关于jQuery UI Slider - 发布时从“幻灯片"事件返回的值与“更改"值不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!