最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using jQuery, how do I disable the click effect on the current tab? - Stack Overflow

programmeradmin2浏览0评论

I have a menu with an animation going on, but I want to disable the click while the animation is happening.

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

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

However, I want to disable all the buttons while the event is happening, AND disable the div that was clicked.

I was thinking of adding a class to the div that's clicked and putting the click only on the divs without that class:

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

But this doesn't appear to work (I think it does logically)?

Any help appreciated.

Cheers,
Steve

I have a menu with an animation going on, but I want to disable the click while the animation is happening.

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

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

However, I want to disable all the buttons while the event is happening, AND disable the div that was clicked.

I was thinking of adding a class to the div that's clicked and putting the click only on the divs without that class:

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

But this doesn't appear to work (I think it does logically)?

Any help appreciated.

Cheers,
Steve

Share Improve this question asked Nov 4, 2008 at 3:15 Steve PerksSteve Perks 5,5304 gold badges30 silver badges41 bronze badges
Add a comment  | 

3 Answers 3

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

You could do something like this...

$(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); });

    });

});

This will animate the click so long as any div is not currently animating. I'm most likely put all those divs in a container and not just simply refer to div, since it could affect a lot more on the page than just your menu,

How do I leave the clicked <div> disabled after the animation's occurred? I've added a class to the div that's been clicked, but doing the following doesn't appear to work:

<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;
});

I suspect I'm missing something with regard to the way .not works

发布评论

评论列表(0)

  1. 暂无评论