Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 身体背景变换器?_Javascript_Jquery_Css_Background_Document Body - Fatal编程技术网

Javascript 身体背景变换器?

Javascript 身体背景变换器?,javascript,jquery,css,background,document-body,Javascript,Jquery,Css,Background,Document Body,好的,给你 简单地说,我希望能够通过CSS淡出身体的背景,并经常改变,然后循环 有没有办法用CSS和jQuery实现这一点 谢谢大家! 您可以使用jquery animate方法,完成后使用新颜色再次调用该方法: var color = ["red","green","blue"]; var i = 0; function changeColor() { // Change to the next color over 2 seconds. When it is done, call th

好的,给你

简单地说,我希望能够通过CSS淡出身体的背景,并经常改变,然后循环

有没有办法用CSS和jQuery实现这一点


谢谢大家!

您可以使用jquery animate方法,完成后使用新颜色再次调用该方法:

var color = ["red","green","blue"];
var i = 0;

function changeColor()
{
 // Change to the next color over 2 seconds.  When it is done, call this method again.
 $("body").animate({"background-color":color[i]}, 2000, changeColor); 
 i++;  // Increment the counter so the next color in the array is shown
 i = i % 3;   // Make sure i is never greater than 2 by using the modulous.
}

changeColor();
看这把小提琴:


太棒了!但是我该如何使用背景图像呢?非常感谢你!你必须使用一个div,然后通过交叉淡入来设置图像的动画。有关更多信息,请参阅此答案: