I am using for a short period ui slider utility and ended with the following situation. I have three sliders combined in order to use their result and alter an object’s css box-shadow. This is my code:
$('#slider2, #slider3, #slider4').slider({
range: 'min',
min: 0,
max: 100,
step: 1,
animate: true,
slide: function(x,y,z) {
var x = $('#slider2').slider('value'),
y = $('#slider3').slider('value'),
z = $('#slider4').slider('value')
$('#xShadowValue').val(x + ' px');
$('#yShadowValue').val(y + ' px');
$('#zShadowValue').val(z + ' px');
$('#target').css('box-shadow', x + 'px ' + y + 'px ' + z + 'px ' + '#888888');
}
});
$('#xShadowValue').val($('#slider2').slider('value') + ' px');
$('#yShadowValue').val($('#slider3').slider('value') + ' px');
$('#zShadowValue').val($('#slider4').slider('value') + ' px');
Problem is when i change the first one all is fine. When i change the second one the first one drops or increases a unit same when i change the third occurs for the second one. Furthermore i cannot slide all of them to 0 or 100. A limit appears at 1 and 99 accordingly. Thanx in advance.
The reason for this is that you are using
$("#slider").slider("value")to retrieve the value.This is not mentioned in the documentation from what I could see, but according to a note in this bug ticket, you should use
ui.valueto get the new value of the slider and thevaluemethod to get the old value of the slider. This explains both of your issues.With that in mind, you have to tweak your code a bit so that you take advantage of
ui.valuefor each slider.I would change two things:
Use
data-*attributes to designate which slider corresponds to which axis:Update your
slidecallback to leverage those attributes:Basically, keep a simple object that tracks x, y, and z. This object is easily updated using the aforementioned
data-*attributes.Example: http://jsfiddle.net/t3gva/