You can add the change
listener and also compare the value
there.
Demo http://jsfiddle.net/WqCkv/1/
Javascript:
//Store frequently elements in variables
var slider = $('#slider'),
tooltip = $('.tooltip');
//Hide the Tooltip at first
tooltip.hide();
//Call the Slider
slider.slider({
//Config
range: "min",
min: 1,
value: 35,
start: function (event, ui) {
tooltip.fadeIn('fast');
},
change: function (event, ui) {
var value = slider.slider('value');
setVolumeImage(value);
},
//Slider Event
slide: function (event, ui) { //When the slider is sliding
var value = slider.slider('value');
setVolumeImage(value);
tooltip.css('left', value).text(ui.value); //Adjust the tooltip accordingly
},
stop: function (event, ui) {
tooltip.fadeOut('fast');
}
});
function setVolumeImage(value) {
volume = $('.volume');
if (value <= 5) {
volume.css('background-position', '0 0');
} else if (value <= 25) {
volume.css('background-position', '0 -25px');
} else if (value <= 75) {
volume.css('background-position', '0 -50px');
} else {
volume.css('background-position', '0 -75px');
}
}