开发者

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

开发者 https://www.devze.com 2023-02-09 21:42 出处:网络
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: \'#f

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

精彩评论

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