jQuery UI Slider - 发布时从'slide'事件返回的值与'change'值不同 [英] jQuery UI Slider - Value returned from 'slide' event on release is different from 'change' value

查看:174
本文介绍了jQuery UI Slider - 发布时从'slide'事件返回的值与'change'值不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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));
    }
});

由于某些奇怪的原因,当释放滑块(mouseup)时,该值会略微改变。幻灯片事件返回的内容与更改事件的内容不同。任何人都有任何想法可能导致这个以及如何解决它?

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 - 发布时从'slide'事件返回的值与'change'值不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆