jQuery帮助解除绑定,然后在动画序列之后再次绑定

jQuery帮助解除绑定,然后在动画序列之后再次绑定,jquery,events,bind,unbind,Jquery,Events,Bind,Unbind,我有下面的js函数,我想防止任何事情发生,并在点击事件发生后排队。然后,当函数结束时,允许再次发生单击事件 $("#tweet_activate a").click(function(){ if($('body').hasClass('home')) { $(this).parent().stop(true,true).animate({top: "+=154"}, 400).delay(1200).fadeOut(); } else { $("#int_comp").animate({

我有下面的js函数,我想防止任何事情发生,并在点击事件发生后排队。然后,当函数结束时,允许再次发生单击事件

$("#tweet_activate a").click(function(){    
if($('body').hasClass('home')) {
$(this).parent().stop(true,true).animate({top: "+=154"}, 400).delay(1200).fadeOut();
} else {
$("#int_comp").animate({width: "+=157"}, 100);
$(this).parent().stop(true,true).animate({top: "+=154"}, 400).delay(1200).fadeOut();
}
$("#tweet_text").delay(400).animate({right: "+=56"}, 400);
$("#tweet").delay(900).animate({right: "+=214"}, 400);
$("#tweet_deactivate").delay(1200).fadeIn();
$("#tweet_text p, #tweet_text span, #tweet #links").delay(1200).fadeIn();
$("#eye").delay(600).fadeOut();
return false;
});

$("#tweet_deactivate a").click(function(){
if($('body').hasClass('home')) {
} else {
$("#int_comp").animate({width: "-=157"}, 400);
}
$("#tweet_text p, #tweet_text span, #tweet #links").fadeOut();
$("#tweet").stop(true,true).animate({right: "-=214"}, 400);
$("#tweet_text").delay(400).animate({right: "-=56"}, 400);
$(this).parent().delay(900).animate({top: "-=154"}, 400).delay(200).fadeOut()
.delay(600).animate({top: "+=154"}, 100);
$("#tweet_activate").animate({top: "-=154"}, 500).delay(650).fadeIn();
$("#eye").delay(1000).fadeIn();
return false;
});
地点在这里-

如果单击右侧图标网格上的加号,您将看到序列发生。如果你在中途点击图标,你会看到它再次开火


谢谢,Matt只需在元素中添加一个小的检查。一旦开始动画,将bool设置为true,单击“使其成为您的第一个检查”

var animating = false;
$("#tweet_activate a").click(function() {
    if (animating !== true) {
        animating = true;
        if ($('body').hasClass('home')) {
            $(this).parent().stop(true, true).animate({
                top: "+=154"
            }, 400).delay(1200).fadeOut();
        } else {
            $("#int_comp").animate({
                width: "+=157"
            }, 100);
            $(this).parent().stop(true, true).animate({
                top: "+=154"
            }, 400).delay(1200).fadeOut();
        }
        $("#tweet_text").delay(400).animate({
            right: "+=56"
        }, 400);
        $("#tweet").delay(900).animate({
            right: "+=214"
        }, 400);
        $("#tweet_deactivate").delay(1200).fadeIn();
        $("#tweet_text p, #tweet_text span, #tweet #links").delay(1200).fadeIn();
        $("#eye").delay(600).fadeOut(function() {
            animating = false; // this is a guess. but place this where ever the animation is stopping. 
        });
    }
    return false;
});
这应该行得通。试试看

$("#tweet_activate a").click(function() {
    $this = $(this);
    if ($this.attr("is-animated") !== "true") {
        $this.attr("is-animated", "true");
        if ($('body').hasClass('home')) {
            $this.parent().stop(true, true).animate({
                top: "+=154"
            }, 400).delay(1200).fadeOut();
        } else {
            $("#int_comp").animate({
                width: "+=157"
            }, 100);
            $this.parent().stop(true, true).animate({
                top: "+=154"
            }, 400).delay(1200).fadeOut();
        }
        $("#tweet_text").delay(400).animate({
            right: "+=56"
        }, 400);
        $("#tweet").delay(900).animate({
            right: "+=214"
        }, 400);
        $("#tweet_deactivate").delay(1200).fadeIn();
        $("#tweet_text p, #tweet_text span, #tweet #links").delay(1200).fadeIn();
        $("#eye").delay(600).fadeOut(function() {
            $this.attr("is-animated", "false");
        });
    }
    return false;
});

您可以看到关键点是属性(“已设置动画”);我无法在主按钮中进行检查,因为在我应用属性之前,主按钮已经定义了单击事件。奇怪。哦,如果你像我在前面的例子中那样,将click事件的内容包装在if语句中,它就会工作。但是,与前面的示例不同,我在这里将属性附加到锚定标记,并读取它以查看它是否处于动画状态。通过这种方式,您可以让多个元素使用这种类型的事件“阻塞”

同时查看代码;您意识到您可以为大多数“定时”内容指定回调函数。所以,你不需要把所有的东西都“延迟”,只需要回拨到下一个动画或淡入淡出效果。嗨,我知道这可能会更有效,但不知道如何。如果你能,请随便举个小例子。谢谢你的魅力。我还在另一段类似的代码上尝试它,但代码以$(“#content_area”).stop(true,true).delay(800).animate({top:-=57”},400);返回false; });我如何将您的修复程序中的最后一部分代码添加到此。我自己没法让它工作。。。函数(){animating=false;});}返回false;});再想想,我不敢相信我没有想到这一点。您可以在jquery中使用
:animated
选择器。给我一分钟,我会用一种新的方法来更新同一个脚本。最后一个解决方案是在单击事件/运动发生时,我向每个链接添加一个类。然后在你最后一个动画之后,我移除这个类,允许再次单击链接。您可以使用类或属性。对于在.attr()上读取的属性,属性包含选择器。属性可能也会更好。天哪,我今天0/2。添加和删除这样的任意类可能会导致冲突。您好,两个更新都不起作用!!原始代码起到了很好的作用。只需要让它为我的另一个街区工作。有点管用。您可以在这里看到完整的代码-直接在tweet函数之后查看块。eye_close click事件不起作用。好的,对不起,昨晚很忙。给我一分钟再看看这个。