开发者

jQuery help with unbind then bind again after animation sequence

I have the following js function and I would like to prevent anything from happening and queueing once the click event has happened. Then when the function ends allow the click event to happen again.

$("#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, #twee开发者_高级运维t #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;
});

The site is here - http://danielhollandphotography.com/

If you click on the 'plus' sign on the right icon grid you'll see the sequence happen. If you click the icon mid way through you'll see it fire again.

Thanks, Matt


Just add a small check to the element.Once you start the animation set a bool to true, on click make that your first check

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

This should work. Give it a try.

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

you can see the key is the attr("is-animated"); I cannot do the check in the main button because that has already defined the click event before I have applied the attribute. Strange. Ohh well, if you wrap the contents of the click event in a if statement like I did in the previous example it works. Unlike the previous example however I am attaching a attribute to the anchor tag here and reading it to see if it is in a state of animation. This way you can have multiple elements with this type of event 'blocking'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜