答案 0 :(得分:2)
您可以使用margin-left
示例:
$(function() {
var slider = $('#slider').slider({
range: 'min',
min: 3,
max: 5,
value:3,
create: function(event, ui) {
var v= $(this).slider('value');
$(this).find('.ui-slider-handle').text(v + ' years');
},
slide: function( event, ui) {
var handle = $( '.ui-slider-handle' ),
handleWidth = handle.width(),
position = handle.position(),
marginLeft;
handle.text(ui.value + ' years');
if(ui.value == 4)
marginLeft = -handleWidth/2-10;
else if(ui.value == 5)
marginLeft = -handleWidth-20;
else
marginLeft = 0;
handle.css('margin-left',marginLeft+'px');
}
});
});
答案 1 :(得分:0)
如果您有多个滑块或带有两个手柄的范围滑块:
$(function() {
var your_slider = $('#slider').slider({
range: 'min',
min: 3,
max: 5,
value:3,
create: function(event, ui) {
var v= $(this).slider('value');
$(this).find('.ui-slider-handle').text(v + ' years');
},
slide: function(event, ui) {
$(ui.handle).text(ui.value + ' years');
var handleWidth = $(ui.handle).width(),
position = $(ui.handle).position(),
marginLeft;
if(ui.value == your_slider.slider( "option", "min" ))
marginLeft = 0;
else if(ui.value == your_slider.slider( "option", "max" ))
marginLeft = -handleWidth;
else
marginLeft = -handleWidth/2;
$(ui.handle).css('margin-left',marginLeft+'px');
}
});
});