Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  33] [ 7]  / answers: 1 / hits: 17723  / 13 Years ago, thu, february 2, 2012, 12:00:00

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?



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.



Here's a fiddle with this oddity in action: http://jsfiddle.net/5W6Zh/



Thanks in advance


More From » jquery

 Answers
32

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).



Use this:



change: function(event, ui) {
$('.values').text(ui.values[0] + ',' + ui.values[1]);
}


Instead of:



change: function(event, ui) {
$('.values').text($(this).slider('values', 0) + ',' + $(this).slider('values', 1));
}


I forked your jsfiddle and made it work:
http://jsfiddle.net/danhixon/9JdhU/1/



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.


[#87667] Wednesday, February 1, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carrington

Total Points: 674
Total Questions: 90
Total Answers: 108

Location: Burundi
Member since Sat, Aug 21, 2021
3 Years ago
;