jQuery-UI slider up down buttons
Didn't find the way to create up and down buttons for vertical slider, to make its appearance like as standard scroller.
Is solution below suitable? Or are there any other ways?
function scroll(step)
{
if (step > 0)
{
if ($("#slider").slider('value') <= (100开发者_JAVA百科 - step))
{
$("#slider").slider('value', $("#slider").slider('value') + step);
}
}
else
{
if ($("#slider").slider('value') >= Math.abs(step))
{
$("#slider").slider('value', $("#slider").slider('value') + step);
}
}
return false;
}
What you have certainly works...but if you're worried about the range capping, slider already does this internally, so you can just do this:
function scroll(step) {
var s = $("#slider");
s.slider('value', s.slider('value') + step);
return false;
}
Also note that even setting the value returns it (the capped value), so you can do this for example:
function scroll(step) {
var s = $("#slider");
var newValue = s.slider('value', s.slider('value') + step);
alert("The new value is: " + newValue);
return false;
}
So for example if the range is 0-100
and you're at 90
, a step of 10
or more would always result in a newValue
of 100
.
精彩评论