jquery restart animation after it stops [duplicate

2019-09-08 06:22发布

Possible Duplicate:
Jquery Continuously Loop Animation

I want this animation to restart when the div timer reaches 940px. So far I have this:

$('.timer').animate({'width':940}, {queue:false, duration:5000, easing: 'linear'});
if ($('.timer').width() == 940){
    $('.timer').width() == 0;
    $('.timer').animate({'width':940}, {queue:false, duration:5000, easing: 'linear'});
}

1条回答
家丑人穷心不美
2楼-- · 2019-09-08 06:49

Restarting animated loop:

$(".timer").bind("animation.loop", function(){
    $(this).animate({width: 940}, 5000, function(){
        $(this).animate({width: 0}, 5000, function(){
            $(this).trigger("animation.loop");
        });
    });
}).trigger("animation.loop");

Do the animation, hard reset, animate again:

$(".timer").bind("animation.loop", function(){
    $(this).animate({width: 940, easing: 'linear'}, 5000, function(){
        $(this).css("width", 0).trigger("animation.loop");
    });
}).trigger("animation.loop");
查看更多
登录 后发表回答