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.
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);
})();
精彩评论