如何“连续地"改变背景颜色.无需刷新页面 [英] How to change background color "continuously" without refreshing the page

查看:74
本文介绍了如何“连续地"改变背景颜色.无需刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有什么方法可以像彩虹一样不断地改变背景颜色吗?

Is here any way to continuously change the background color like a rainbow?

推荐答案

希望您需要类似的东西.

Hope you needed something like this.

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>

这篇关于如何“连续地"改变背景颜色.无需刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆