Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a jquery infinite animation?

I'm trying to implement a jQuery function with an infinite loop to animate the body background with 3 colours. I cannot think of a nice and clean solution. Something like this?

$(document).ready(function(){                
     $('body').animate({backgroundColor:'#ffcc00'}, 500, function(){
        $('body').animate({backgroundColor:'#eeeeee'}, 500, function(){
           $('body').animate({backgroundColor:'#3b5998'}, 500);
       });
   });
});

Any idea?

like image 549
Mauro74 Avatar asked Jan 17 '11 13:01

Mauro74


1 Answers

$(document).ready(function(){
    function animate() {
        $('body').animate({backgroundColor:'#ffcc00'}, 500, function(){
            $('body').animate({backgroundColor:'#eeeeee'}, 500, function(){
                $('body').animate({backgroundColor:'#3b5998'}, 500, function(){
                    animate();
                });
            });
        });
    }
    animate();
});
like image 129
Cesar Avatar answered Sep 19 '22 06:09

Cesar