执行功能以避免其间的任何其他点击事件

时间:2013-05-25 16:05:13

标签: jquery html css

在div点击事件我希望禁用点击事件图像如何做到这一点?我尝试解除绑定但它似乎只有在事件是bind()??

时才有效
$(div).click(function ()
{
//disabled click for images while function Executes 

});

2 个答案:

答案 0 :(得分:0)

你可以做的是:

var clickEnabled = true;
$(img).click(function (){
   if (!clickEnabled) return;
   // do your stuff
});

$(div).click(function (){
  //start animation
  clickEnabled = false;

  setTimeout(function(){
     //end animation
     clickEnabled = true;
  }, 666);
});

答案 1 :(得分:0)

var areWeAllowedToDoStuff = true;

$(div).click(function () {
  areWeAllowedToDoStuff = false;
  $.start_whatever_animation(
    …, // additional animation parameters
    function() { // callback for when animation has finished
      areWeAllowedToDoStuff = true;
    }
  );
});

$("image").click(function() {
  if(!areWeAllowedToDoStuff) {
    return;
  }
  // do other stuff here
});