This question already has answers here:
How to make background color of div tag keep changing using JQuery?
                                
                                    (3个答案)
                                
                        
                                3年前关闭。
            
                    
有什么办法可以像彩虹一样连续改变背景颜色吗?

最佳答案

希望你需要这样的东西。



var body = $('body');
var colors = ['red', 'green', 'blue', 'yellow', 'pink', 'purple'];
var currentIndex = 0;
setInterval(function () {
   body.css({
     backgroundColor: colors[currentIndex]
   });
   if (!colors[currentIndex]) {
       currentIndex = 0;
   } else {
       currentIndex++;
   }
}, 100);

body {
  transition: 200ms ease;
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

关于javascript - 如何在不刷新页面的情况下“连续”更改背景颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41099739/

10-12 00:58