开发者

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.


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);
})();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜