我在Javascript中具有此事件函数: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');
},
//Slider Event
slide: function(event, ui) { //When the slider is sliding
var value = slider.slider('value'),
volume = $('.volume');
tooltip.css('left', value).text(ui.value); //Adjust the tooltip accordingly
$.ajax({
dataType: "text",
type: "POST",
url: '/setVolume/',
data: { volume_to_set: ui.value},
success: function(data) {
}
});
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');
};
},
stop: function(event,ui) {
tooltip.fadeOut('fast');
},
});
一切工作正常,但是我已经看到,当我移动滑块时,它可能会变成很多请求,如果将其更改为10到30,则实际上会发送20个ajax请求。这不是那么有效...我正在尝试一种方法,它只能识别滑动运动的“终点”,然后才运行AJAX请求。有任何想法吗?
从中删除slide
并将其添加到stop
stop: function(event,ui) {
tooltip.fadeOut('fast');
/* Ajax call here */
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句