解决此问题的方法是:
由于默认情况下滑块实际上不起作用,所以在开始时不要调用任何东西
创建一个JavaScript
函数,当鼠标在滑块内按住时设置滑块的值。
您需要使 ui-slide-handle 在被按住时返回对其父级的引用
此解决方案适用于所有主要浏览器:
$(function(){
$('iframe').ready(function(){
var $document = $('#result iframe',$('#main').contents()).contents();
$('.slider',$document).slider({
//Prevent the slider from doing anything from the start
start:function(event,ui){return false;}
});
$(document).mouseup(function(){
$('.slider,.ui-slider-handle',$document).unbind('mousemove')
})
//While the ui-slider-handle is being held down reference it parent.
$('.ui-slider-handle',$document).mousedown(function(e){
e.preventDefault();
return $(this).parent().mousedown()})
//This will prevent the slider from moving if the mouse is taken out of the
//slider area before the mouse down has been released.
$('.slider',$document).hover(function(){
$('.slider',$document).mousedown(function(){
$(this).bind('mousemove',function(e){
//calculate the correct position of the slider set the value
$(this).slider('value',e.pageX*100/$(this).width())
});
}).mouseup(function(){
$(this).unbind('mousemove');
})},function(){
$( '.slider',$document ).unbind('mousemove');
})
})
});
解决方案链接:
解决方案