使用jQuery,如何禁用当前选项卡上的点击效果?

Using jQuery, how do I disable the click effect on the current tab?

提问人:Steve Perks 提问时间:11/4/2008 更新时间:11/5/2008 访问量:25133

问:

我有一个正在播放动画的菜单,但我想在动画发生时禁用单击。

<div></div>
<div></div>
<div></div>

$("div").click(function() { 
  $(this).animate({height: "200px"}, 2000); 
  return false;
});

但是,我想在事件发生时禁用所有按钮,并禁用单击的 div。

我正在考虑将一个类添加到被单击的 div 中,并仅将单击放在没有该类的 div 上:

$("div").not("clicked").click(function() { 
  $(this).animate({height: "200px"}, 2000).addClass("clicked"); 
  return false;
});

但这似乎不起作用(我认为它在逻辑上确实如此)?

任何帮助表示赞赏。

干杯,
史蒂夫

JavaScript jQuery

评论


答:

16赞 Markus Jarderot 11/4/2008 #1
$("div").click(function() {
    if (!$(this).parent().children().is(':animated')) {
        $(this).animate({height: "200px"}, 2000); 
    }
    return false;
});

评论

1赞 Martin 1/8/2010
W00t! 14个月后解决了我的问题。
0赞 hugoware 11/4/2008 #2

你可以做这样的事情......

$(function() {          
    $("div").click(function() {                 

        //check to see if any of the divs are animating
        if ($("div").is(":animated")) { 
            alert("busy"); 
            return; 
        }

        //whatever your animation is        
        var div = $(this);
        div.slideUp(3000, function(){ div.slideDown(1000); });

    });

});

只要任何 div 当前没有动画,这将对单击进行动画处理。我很可能将所有这些 div 放在一个容器中,而不仅仅是简单地引用 div,因为它可能会影响页面上的更多内容,而不仅仅是您的菜单,

0赞 Steve Perks 11/5/2008 #3

如何在动画发生后禁用单击的 <div>?我已将一个类添加到已单击的 div 中,但执行以下操作似乎不起作用:

<div></div>
<div class="active"></div>
<div></div>

$("div").not('active').click(function() {
  if (!$(this).parent().children().is(':animated')) {
    $(this).animate({height: "200px"}, 2000); 
  }
  return false;
});

我怀疑我遗漏了一些关于.not工作方式的东西