【发布时间】:2013-01-04 07:53:18
【问题描述】:
我有这个代码:
$(document).ready(function(){
$(".subscriptions").click(function (){
if($(".pollSlider").css("margin-right") == "-200px"){
$('.pollSlider').animate({"margin-right": '+=200'});
}else{
$('.pollSlider').animate({"margin-right": '-=200'});
}
});
//other exceptions
if($(".pollSlider").css("margin-right") > "200px"){
$(".pollSlider").css({'margin-righ':'200px'});
}
if($(".pollSlider").css("margin-right") < "0px"){
$(".pollSlider").css({'margin-righ':'0px'});
}
});
这是css:
.pollSlider{
overflow: auto;
top:0px;
position:fixed;
height:100%;
background:red;
width:200px;
right:0px;
margin-right: -200px;
z-index:100;
}
我有一个 div,当用户单击一个按钮时,div 从左侧 200px 滑入屏幕,当用户再次单击同一个按钮时,div 动画向右 200px。这个系统工作得很好,但问题是,如果用户在 div 向左或向右动画时继续单击,则 div 将在屏幕之外(向右)动画,并且当用户再次单击时不会再次返回。所以我尝试添加 //other 异常,但那些 if 语句不起作用。我该如何解决这个问题?
【问题讨论】:
-
你试过在
.animate()之前使用.stop()吗? -
这样 $('.pollSlider').stop(); ??
-
是的,它应该类似于
$('.pollSlider').stop().animate()
标签: javascript jquery html css jquery-ui