Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animate() not working continuously

I want to animate #ani continuously using animate() in jQuery. My code only works one time. How do I make this animation loop?

Here is my code, and you can see an online demo here.

HTML

<div id="ani">animation</div>

SCRIPT

$('#ani').css('position','absolute');

setTimeout(function(){
    $('#ani').animate({top:'-10px'},2000)
},100);

setTimeout(function(){
    $('#ani').animate({top:'20px'},2000)
},100);
like image 209
Kamal Avatar asked Feb 05 '26 13:02

Kamal


1 Answers

$('#ani').css('position','absolute');
function loop(){
    $('#ani').animate({top:'-10px'},2000,function(){
        $('#ani').animate({top:'20px'},2000,function(){
               loop();            
        }) ;                
    })    

}
loop()               

I think you can see the modified online demo: http://jsfiddle.net/9hN2g/5/

like image 82
movever Avatar answered Feb 08 '26 03:02

movever



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!