admin管理员组文章数量:1316666
On my page I have several sliders. They all need the same scale, but some of them go to 150, and some go to 200. I would like to set the max of them all to 200, but prevent some of them from moving passed 150. They are different $().slider() calls, so I'm simply interested in how to set the max of a slider to 200, but not allow any movement past 150...
I would think that this kind of behavior would be built-in, but apparently not?
FYI: I am using range: "min" for these sliders.
EDIT
/
On my page I have several sliders. They all need the same scale, but some of them go to 150, and some go to 200. I would like to set the max of them all to 200, but prevent some of them from moving passed 150. They are different $().slider() calls, so I'm simply interested in how to set the max of a slider to 200, but not allow any movement past 150...
I would think that this kind of behavior would be built-in, but apparently not?
FYI: I am using range: "min" for these sliders.
EDIT
http://jsfiddle/D9nAx/1/
Share Improve this question edited Sep 14, 2012 at 18:56 Erik Funkenbusch 93.5k29 gold badges201 silver badges292 bronze badges asked Sep 14, 2012 at 18:08 S16S16 2,9959 gold badges43 silver badges64 bronze badges 3- 1 Please add the relevant HTML and/or scripts/css to your post so we can improve on top of what you have. In addition if you can create a fidde on jsFiddle that would also alow us to try out different solutions. – Nope Commented Sep 14, 2012 at 18:16
- I'm sure you can use the slider events to control its behaviour. – Musa Commented Sep 14, 2012 at 18:20
- link added: jsfiddle/D9nAx/1 – S16 Commented Sep 14, 2012 at 18:51
2 Answers
Reset to default 7use slide event:
$( "#slider-vertical" ).slider({
orientation: "vertical",
range: "min",
min: 0,
max: 200,
value: 60,
slide: function( event, ui ) {
if(ui.value> 150)
return false;
$( "#amount" ).val( ui.value );
}
});
fiddle : http://jsfiddle/dvz8E
$( "#slider-vertical" ).slider({
orientation: "vertical",
range: "min",
min: 0,
max: 200,
value: 60,
slide: slide
});
function slide(event, ui){
var result = true;
if (ui.value > 150){
$(this).slider( "value" , 150 );
result = false;
}
$( "#amount" ).val( $(this).slider( "value") );
return result;
}
http://jsfiddle/D9nAx/2/
本文标签: javascriptStopping the jQuery UI slider from moving past a given valueStack Overflow
版权声明:本文标题:javascript - Stopping the jQuery UI slider from moving past a given value? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742003681a2411529.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论