farade
farade

Reputation: 11

How make up an infinite loop of two jQuery animation effects?

How make up an infinite loop of two jQuery animation effects: one does $('body').animate({backgroundColor: '#000'}, 'slow');, after that the other does $('body').animate({backgroundColor: '#fff'}, 'slow');, then start over again: from #000 to '#fff'. All that in an infinite loop.

Upvotes: 1

Views: 4436

Answers (1)

user113716
user113716

Reputation: 322452

Example: http://jsfiddle.net/YS5DE/

var $body = $(document.body),cycle;

(cycle = function() {
   $body.animate({backgroundColor:"#000"}, 'slow')
        .animate({backgroundColor:"#FFF"}, 'slow',cycle);
})();

You can easily add in some delays if you want:

Example: http://jsfiddle.net/YS5DE/1/

var $body = $(document.body),cycle;

(cycle = function() {
   $body.delay(1000)
        .animate({backgroundColor:"#000"}, 'slow')
        .delay(1000)
        .animate({backgroundColor:"#FFF"}, 'slow',cycle);
})();

Upvotes: 11

Related Questions