How to re-run animation after animation finishes (jQuery)?

半世苍凉 提交于 2020-01-06 17:15:19

问题


What I am trying to do is to animate an image across the page, continuously, while being draggable at the same time. Currently, it moves across, is draggable, and goes back to the initial position after the initial animation is done.

However, I don't know how to get it to run again so that it's a continuous loop of animation. I was thinking to put the function animateCloud() inside animateCloud() but not sure where to attach it. Below is the jsFiddle demo:

http://jsfiddle.net/iamacatperson/SfFgt/2/

I would also appreciate if there's a better method of doing this. I am just starting to learn jQuery and I only know a couple of syntax.


回答1:


I don't know why are you using .stop() but I guess this should work-

function animateCloud() {
    $(cloud).animate({
        left: '300px'
    }, 25000, function() {
        $(this).css({ left: '0' });
         animateCloud();
    });

}

I hope this is what you want.



来源:https://stackoverflow.com/questions/7271112/how-to-re-run-animation-after-animation-finishes-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!