jQuery sliders control each other
I have created two sliders with jQuery but each slider controls the other, how can I resolve this?
$(function() {
$.extend($.ui.slider.defaults, {
handle: ".slider-handle",
min: 0,
max: 45,
start: function(e,ui){ },
slide: function(e,ui){
var handleVal = $(".slider-bar").slider("value");
$(".slider-handle").css('left', handleVal);
},
stop: function(e,ui){
if($(".slider-handle").position().left >= 38){
$(".slider-handle").animate({left: 44}, 200 );
}
else {
$(".slider-handle").animate({left: 0}, 200 );
}
开发者_如何学运维 }),
$("#slider1").slider();
$("#slider2").slider();
});
When you say var handleVal = $(".slider-bar").slider("value");
, all the sliders on the page are selected because they all have the same class = "slide-bar"
property.
Instead of $(".slider-bar")
, use $this
.
精彩评论